Module: Ordinal
- Included in:
- Numeric
- Defined in:
- lib/ordinal.rb,
lib/ordinal/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
Instance Method Details
#suffixes ⇒ Object
21 22 23 |
# File 'lib/ordinal.rb', line 21 def suffixes ['th','st','nd','rd','th','th','th','th','th','th'] end |
#to_ordinal ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ordinal.rb', line 5 def to_ordinal number = self.to_i case when number == 0 0.to_s when (number % 100 >= 11 and number % 100 <= 13) number.to_s << 'th' else number.to_s << suffixes[number % 10] end end |