0

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?

ScottJShea
  • 7,041
  • 11
  • 44
  • 67

1 Answers1

1

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.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • Thank you! This exposed other issues I had with the environment/tests – ScottJShea Apr 04 '12 at 21:16
  • 1
    You can also check `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 Apr 04 '12 at 21:42
  • I do not think `source_location` is available to me in the Ruby 1.8.7 I am tied to. – ScottJShea Apr 04 '12 at 22:03