Class: Fixnum

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

Instance Method Summary collapse

Instance Method Details

#ordinalObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ext/ext.rb', line 26

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