Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/githubchart.rb

Overview

Add helper methods to Integer

Instance Method Summary collapse

Instance Method Details

#ordinalizeObject

Add ordinalize to simplify converting to spoken string



100
101
102
103
104
105
106
107
108
109
# File 'lib/githubchart.rb', line 100

def ordinalize
  return to_s if zero?
  return "#{self}th" if (11..13).cover?(abs % 100)
  case abs % 10
  when 1 then "#{self}st"
  when 2 then "#{self}nd"
  when 3 then "#{self}rd"
  else "#{self}th"
  end
end