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


83
84
85
86
87
88
89
90
91
92
# File 'lib/githubchart.rb', line 83

def ordinalize
  return to_s if self.zero?
  return "#{self}th" if (11..13).include?(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