Advertisement
Guest User

Date Ordinal

a guest
Mar 22nd, 2012
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.51 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. class Fixnum
  4.     def ordinalize
  5.         if (11..13).include?(self % 100)
  6.             "th"
  7.         else
  8.             case self % 10
  9.             when 1; "st"
  10.             when 2; "nd"
  11.             when 3; "rd"
  12.             else    "th"
  13.             end
  14.         end
  15.     end
  16. end
  17.  
  18. # following line is broken for 11-19 (and for other cases)
  19. #print ["th","st","nd","rd","th","th","th","th","th","th"][Time.now.day.to_s[-1,1].to_i]
  20. now = Time.now
  21. puts now.strftime("#{now.day.ordinalize}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement