Skip to content

Instantly share code, notes, and snippets.

@alterisian
Created November 27, 2012 13:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alterisian/4154152 to your computer and use it in GitHub Desktop.
Save alterisian/4154152 to your computer and use it in GitHub Desktop.
Adds ordinalize i.e. th,st,rd to a number for use in date string outputs
class Fixnum
def ordinalize
if (11..13).include?(self % 100)
"#{self}th"
else
case self % 10
when 1; "#{self}st"
when 2; "#{self}nd"
when 3; "#{self}rd"
else "#{self}th"
end
end
end
end
@mblythe86
Copy link

Doesn't work correctly for negative numbers. See my fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment