Created
April 18, 2011 04:15
-
-
Save vdh/924805 to your computer and use it in GitHub Desktop.
Ruby class for ordinal numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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