2

我正在尝试将救援语句添加到否则失败的 gem。问题是我没有正确地覆盖原始 gem 的方法。我怎样才能做到这一点?

原始宝石

module OmniAuth
  class Configuration
    include Singleton
      def add_camelization(name, camelized)
        self.camelizations[name.to_s] = camelized.to_s
      end

初始化程序/omniauth.rb

module OmniAuth
  class Configuration
    def add_camelization(name, camelized)
      begin
        self.camelizations[name.to_s] = camelized.to_s
      rescue
        puts "No camelization for #{camelized}"
      end
      # ^ This rescue statement is not being called to replace the original gem's method.
    end
  end
end
4

1 回答 1

8

尝试

OmniAuth::Configuration.class_eval do
    def add_camelization(name, camelized)
        ...
    end
end
于 2013-01-21T17:04:28.497 回答