Create a gist now

Instantly share code, notes, and snippets.

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

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