Sha256: fbc74b72007e9233ff446006faac83e6b7fa432d676f6bf67e1cade276532ac7

Contents?: true

Size: 395 Bytes

Versions: 2

Compression:

Stored size: 395 Bytes

Contents

# There is already a Fixnum#ordinalize
class Integer
  ORDINALS = %w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quarter_system-0.1.2 lib/quarter_system/integer.rb
quarter_system-0.1.1 lib/quarter_system/integer.rb