Ruby formatting for ordinals: '1' as '1st', '2' as '2nd' etc
Is anything baked into ruby or r开发者_如何学运维ails to handle formatting for ordinals: '1' as '1st', '2' as '2nd', etc.?
Looks like you are looking for ordinalize:
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.
精彩评论