Skip to content

Instantly share code, notes, and snippets.

@crantok
Created December 4, 2018 15:55
Show Gist options
  • Save crantok/0718f3c30fc70a18bd697b72ac716fbd to your computer and use it in GitHub Desktop.
Save crantok/0718f3c30fc70a18bd697b72ac716fbd to your computer and use it in GitHub Desktop.
Get an english ordinal string ('1st', '2nd', '3rd', etc) from an integer
def english_ordinal n
str = n.to_s
str +
case str
when /11$/, /12$/, /13$/
'th'
when /1$/
'st'
when /2$/
'nd'
when /3$/
'rd'
else
'th'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment