public
Created

Adds ordinalize i.e. th,st,rd to a number for use in date string outputs

  • Download Gist
fixnum_ordinalize.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.