Sha256: 46fe225a39eedce79e6d99145608e7927ead5a547c65feb8a3f7bad5c28d7f2e

Contents?: true

Size: 411 Bytes

Versions: 54

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

54 entries across 54 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.5.0 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.4.2 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.4.1 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.4.0 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.7 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.6 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.5 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.4 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.3 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.2 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.1 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.3.0 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.2.0 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.1.1 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.1.0 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.0.8 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.0.7 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.0.6 lib/all/sugarcube-numbers/fixnum.rb
sugarcube-3.0.5 lib/all/sugarcube-numbers/fixnum.rb