Class: Integer

Inherits:
Object show all
Defined in:
lib/quarter_system/integer.rb

Overview

There is already a Fixnum#ordinalize

Constant Summary collapse

ORDINALS =
%w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)

Instance Method Summary collapse

Instance Method Details

#ordinal(nonnumeric = false) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/quarter_system/integer.rb', line 4

def ordinal(nonnumeric=false)
  if nonnumeric && (1..ORDINALS.size.succ).include?(self)
    ORDINALS[pred]
  elsif nonnumeric
    to_s + ([ [ nil, 'st','nd','rd' ], [] ][self / 10 == 1 && 1 || 0][self % 10] || 'th')
  end
end