Word with an 'S' if quantity > 1

Discussion in 'Ruby' started by Guillaume Loader, Feb 18, 2009.

  1. Hello everyone!

    Is there a method to add an 'S' to a word if there are more than 1 ?

    For example : 1 day / 2 days ...

    Or do I need to create an if statement?

    Thank you!
    --
    Posted via http://www.ruby-forum.com/.
    Guillaume Loader, Feb 18, 2009
    #1
    1. Advertising

  2. Guillaume Loader

    snex Guest

    On Feb 18, 1:29 pm, Guillaume Loader <> wrote:
    > Hello everyone!
    >
    > Is there a method to add an 'S' to a word if there are more than 1 ?
    >
    > For example : 1 day / 2 days ...
    >
    > Or do I need to create an if statement?
    >
    > Thank you!
    > --
    > Posted viahttp://www.ruby-forum.com/.


    try String#pluralize from the active_support gem
    snex, Feb 18, 2009
    #2
    1. Advertising

  3. On Feb 18, 2009, at 2:39 PM, snex wrote:

    > On Feb 18, 1:29 pm, Guillaume Loader <> wrote:
    >> Hello everyone!
    >>
    >> Is there a method to add an 'S' to a word if there are more than 1 ?
    >>
    >> For example : 1 day / 2 days ...
    >>
    >> Or do I need to create an if statement?
    >>
    >> Thank you!
    >> --
    >> Posted viahttp://www.ruby-forum.com/.

    >
    > try String#pluralize from the active_support gem



    Or roll your own if you have a simple need:

    3.times do |n|
    puts "call me in #{n} day#{'s' unless n==1}"
    end
    call me in 0 days
    call me in 1 day
    call me in 2 days
    => 3

    But if you don't know the noun that you'll be counting ('day'), then
    the Inflector from ActiveSupport is the way to go. (snex's
    recommendation of String#pluralize uses the Inflector internally).


    -Rob

    Rob Biedenharn http://agileconsultingllc.com
    Rob Biedenharn, Feb 18, 2009
    #3
  4. Guillaume Loader, Feb 18, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nav

    time quantity in vhdl

    Nav, Oct 1, 2003, in forum: VHDL
    Replies:
    3
    Views:
    16,216
  2. Gary Vidal
    Replies:
    2
    Views:
    1,866
    Steven Cheng[MSFT]
    Feb 12, 2004
  3. Przemek Klein
    Replies:
    0
    Views:
    362
    Przemek Klein
    Oct 6, 2005
  4. Replies:
    3
    Views:
    297
    Earl Purple
    May 17, 2006
  5. bart
    Replies:
    14
    Views:
    755
Loading...

Share This Page