Guest User

Untitled

a guest
Aug 27th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.71 KB | None | 0 0
  1. module TimeExtender
  2.   using TimeFormatter
  3.   puts Time.now.format_to_my_datetime("-05:00")
  4.   # in Rails, time is often translated into an ActiveSupport::TimeWithZone object
  5.   refine ActiveSupport::TimeWithZone do
  6.     # iputs Time.now.format_to_my_datetime("-05:00")
  7.     def method_missing(method, *args)
  8.       # Time cant respond_to? refinements no matter where I try a `using` call because
  9.       # Kernel methods for reflection are not in Ruby yet
  10.       # http://stackoverflow.com/questions/15263261/why-does-send-fail-with-ruby-2-0-refinement
  11.       #if Time.respond_to?(method.to_sym)
  12.         self.to_time.send(method.to_sym, args.first)
  13.       #end
  14.     end
  15.   end
  16.   puts Time.now.format_to_my_datetime("-05:00")
  17. end
Advertisement
Add Comment
Please, Sign In to add comment