Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

mblythe86 commented Mar 9, 2016

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