Method: Fusu::String::Methods#ordinal
- Defined in:
- lib/fusu/string/methods.rb
#ordinal(number) ⇒ Object
Returns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
ordinal(1) # => "st"
ordinal(2) # => "nd"
ordinal(1002) # => "nd"
ordinal(1003) # => "rd"
ordinal(-11) # => "th"
ordinal(-1021) # => "st"
282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/fusu/string/methods.rb', line 282 def ordinal(number) abs_number = number.to_i.abs if (11..13).include?(abs_number % 100) "th" else case abs_number % 10 when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end |