I need to Monkey patch strftime in Ruby 1.8.7 with Rails 2.3 on Windows. In config\initializers I put this time_patch.rb file (code below) but it does not seem to be picking up:
if RUBY_PLATFORM =~ /mingw32|mingw64|mswin32|mswin64/
class Time
alias_method :original_strftime, :strftime
def strftime(fmt)
hour12 = "%2d" % ((hour + 11) % 12 + 1)
original_strftime(fmt.gsub(/%l/, hour12))
end
end
end
I renamed the method to def blorping
and did Time.methods
from the Rails console but did not see the new method.
What do I need to do to get it to work?
You're checking the class methods when using Time.methods
, so what you want is something like Time.instance_methods
to be sure it's patched correctly.
Time.instance_method(:strftime).source_location
in Ruby 1.9 to see where the method is defined. The internal one should return nil
, a sign it's probably implemented in C in the Ruby VM, but yours would show the source location - tadman 2012-04-04 21:42
source_location
is available to me in the Ruby 1.8.7 I am tied to - ScottJShea 2012-04-04 22:03