you are in: codestackercodes [RSS]turning numbers into ordinals

turning numbers into ordinals Delicious Email

show/hide lines
   1  def ordinal(rank) 
   2    result = case rank 
   3      when 4..20: h(rank) + "th" 
   4      else 
   5      result = case (rank.modulo(10)) 
   6        when 1: h(rank) + "st" 
   7        when 2: h(rank) + "nd" 
   8        when 3: h(rank) + "rd" 
   9        else h(rank) + "th" 
  10      end 
  11    end 
  12    result 
  13  end
created by leozera — 29 September 2008 — get a short url — tags: number ruby embed

Comments



We dont send spam :)

If checked, it's highlights your comment
simple_captcha.jpg
Are you a human? Type the code from the image