method

ordinal

Importance_2
ordinal(number) public

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"
Show source
Register or log in to add new notes.
December 9, 2017 - (<= v3.2.13)
0 thanks

Getting just the ordinal on Rails 3.

The ordinal method isn’t publicly available in Rails 3 so you can do something like this:

ordinal(1).last(2) #=> "st"

ordinal(20).last(2) #=> "th"
January 29, 2018 - (<= v3.2.13)
0 thanks

Correction: Getting just the ordinal on Rails 3.

The ordinal method isn’t publicly available in Rails 3 so you can do something like this:

ordinalize(1).last(2) #=> "st"

ordinalize(20).last(2) #=> "th"