Skip to content

Instantly share code, notes, and snippets.

@alterisian
Created November 27, 2012 13:07
Show Gist options
  • Select an option

  • Save alterisian/4154152 to your computer and use it in GitHub Desktop.

Select an option

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
@alterisian
Copy link
Copy Markdown
Author

@mblythe86
Copy link
Copy Markdown

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