Sha256: 0764eec383307e98edfe37e08916c8f3e366d55820d17040ace595a237dfde66

Contents?: true

Size: 411 Bytes

Versions: 43

Compression:

Stored size: 411 Bytes

Contents

class Fixnum

  def nth
    # if the first two digits of rank are between 11 and 20, it's an
    # 'up-teenth' kinda number
    modulo_100 = self % 100
    if modulo_100 < 10 || modulo_100 > 20
      case self % 10
      when 1
        return "st"
      when 2
        return "nd"
      when 3
        return "rd"
      end
    end

    return "th"
  end

  def ordinalize
    return "#{self}#{nth}"
  end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
sugarcube-1.7.0 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.6.3 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.6.2 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.6.1 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.6.0 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.9 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.8 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.7 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.6 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.5 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.4 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.3 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.2 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.1 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.5.0 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.4.6 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.4.5 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.4.4 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.4.3 lib/sugarcube-numbers/fixnum.rb
sugarcube-1.4.2 lib/sugarcube-numbers/fixnum.rb