Skip to content

Instantly share code, notes, and snippets.

@vdh
Created April 18, 2011 04:15
Show Gist options
  • Save vdh/924805 to your computer and use it in GitHub Desktop.
Save vdh/924805 to your computer and use it in GitHub Desktop.
Ruby class for ordinal numbers
class Integer
def ordinal
cardinal = self.abs
digit = cardinal%10
if (1..3).include?(digit) and not (11..13).include?(cardinal%100)
self.to_s << %w{st nd rd}[digit-1]
else
self.to_s << 'th'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment