CommonThread

Tip: Ruby on Rails Ordinalize

Posted by anthony crumley, Thu Nov 22 07:00:00 UTC 2007

The Ruby on Rails framework is chock full of interesting little nuggets. Ordinalize is a number extension that returns the corresponding ordinal number as a string. For instance, 1.ordinalize returns “1st” and 22.ordinalize return “22nd”.

Example:

place = 3
puts "You are currently in #{place.ordinalize} place." 

Result:

You are currently in 3rd place.

Filed Under: | Tags:

Comments

Have your say

A name is required. You may use HTML in your comments.




Categories