Topic: Turning "22" into "22nd", "1" into "1st", etc, etc.

I've written the following method to add "st", "nd", "rd" or "th" to the end of a number to make it nicer for dates or other numbers representing a position. Any suggestions for how to make it more concise? I would've liked to not add the 0 at the beginning but the numbers 11, 12 and 13 make life harder..

def numeric_position(number)
  return number if number == 0

  # Add a 0 to the begining if there is none to start with
  number = "0" + number.to_s unless number =~ /(\d\d)$/

  # Check the last two digits and set the extension
  case number.to_s
  when /(01|21|31|41|51|61|71|81|91)$/ then ext = "st"
  when /(02|22|32|42|52|62|72|82|92)$/ then ext = "nd"
  when /(03|23|33|43|53|63|73|83|93)$/ then ext = "rd"
  else ext = "th"

  # Strip the leading 0 if there is one and add to the extension
  return number.to_s.sub(/^0/, '') + ext

Thanks in advance for any advice.

Re: Turning "22" into "22nd", "1" into "1st", etc, etc.

rails has a method for this:

1.ordinalize    # => "1st"
2.ordinalize    # => "2nd"
1002.ordinalize # => "1002nd"
1003.ordinalize # => "1003rd"

Re: Turning "22" into "22nd", "1" into "1st", etc, etc.

Doh! I thought that might be the case but couldn't think of what it might be called. Thanks!