Вопрос

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top