Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Word with an 'S' if quantity > 1
Guillaume Loader
2/18/2009 7:29:00 PM
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-...
.
3 Answers
snex
2/18/2009 7:40:00 PM
0
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 via
http://www.ruby-...
.
try String#pluralize from the active_support gem
Rob Biedenharn
2/18/2009 8:00:00 PM
0
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 via
http://www.ruby-...
.
>
> 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://agileconsult...
Rob@AgileConsultingLLC.com
Guillaume Loader
2/18/2009 9:42:00 PM
0
I used your code Rob and it works fine! Thanks :)
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Word with an 'S' if quantity > 1
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password