Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Word with an 'S' if quantity > 1

Reply
Thread Tools

Word with an 'S' if quantity > 1

 
 
Guillaume Loader
Guest
Posts: n/a
 
      02-18-2009
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/.

 
Reply With Quote
 
 
 
 
snex
Guest
Posts: n/a
 
      02-18-2009
On Feb 18, 1:29*pm, Guillaume Loader <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Rob Biedenharn
Guest
Posts: n/a
 
      02-18-2009
On Feb 18, 2009, at 2:39 PM, snex wrote:

> On Feb 18, 1:29 pm, Guillaume Loader <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
Guillaume Loader
Guest
Posts: n/a
 
      02-18-2009
I used your code Rob and it works fine! Thanks

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps HAOBBoy@gmail.com C++ 3 05-17-2006 09:02 AM
quantity of JPS's/Servlets vs. resource consuming Przemek Klein Java 0 10-06-2005 12:20 PM
Saving The quantity of a textbox control between postbacks Gary Vidal ASP .Net 2 02-12-2004 01:04 AM
FS: Lucent ClearTrac V352, SDM-9350 Routers, $100 each, quantity of 20 available, must get these cleared out of our bank inventory Pudda Work VOIP 0 12-24-2003 07:32 PM
time quantity in vhdl Nav VHDL 3 10-02-2003 02:41 PM



Advertisments