Class: Fixnum

Inherits:
Object show all
Defined in:
lib/ext.rb

Instance Method Summary collapse

Instance Method Details

#ordinalObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ext.rb', line 10

def ordinal
  # 1 => 1st
  # 2 => 2nd
  # 3 => 3rd
  # ...
  case self % 100
    when 11..13; "#{self}th"
  else
    case self % 10
      when 1; "#{self}st"
      when 2; "#{self}nd"
      when 3; "#{self}rd"
      else    "#{self}th"
    end
  end
end