On Feb 18, 2009, at 2:39 PM, snex wrote:
> On Feb 18, 1:29 pm, Guillaume Loader <picpi...@hotmail.com> 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