Advertisement
saasbook

time_extension_example.rb

Jan 10th, 2012
1,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.43 KB | None | 0 0
  1. #  Note: Time.now returns current time as seconds since epoch
  2. class Fixnum
  3.   def seconds  ; self ; end
  4.   def minutes  ; self * 60 ; end
  5.   def hours    ; self * 60 * 60 ; end
  6.   def ago      ; Time.now - self ; end
  7.   def from_now ; Time.now + self ; end
  8. end
  9. Time.now    
  10. # => Mon Nov 07 10:18:10 -0800 2011
  11. 5.minutes.ago
  12. # => Mon Nov 07 10:13:15 -0800 2011
  13. 5.minutes - 4.minutes
  14. # => 60
  15. 3.hours.from_now
  16. # => Mon Nov 07 13:18:15 -0800 2011
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement