I'm trying to do some monkey patching in ActiveShipping UPS class .
I need to add a class level method (starting with .self), so here it's what I'm trying to do:
module ActiveMerchant module Shipping class UPS < Carrier def self.process_request(receiver, sender, packages, options = {}) # some code end def regular_method "foobar" end end end end Unfortunately when I'm trying to use it:
ActiveMerchant::Shipping::UPS.process_request(receiver etc) I get an error:
NoMethodError: undefined method `process_request' for ActiveMerchant::Shipping::UPS:Class from (irb):6 from C:/Ruby19/bin/irb.bat:19:in `<main>' There is no class method named process_request in original class.
In original UPS class provided in gem there is one static method defined self.retry_safe = true and I can use it without errors.
I can also use regular_method after creating instance of UPS class.
More details provided:
I'm working with Rails 2.3 ( :-( ) and Ruby 1.9.2. I have no influce on environment.
Monkey patched code is under plugins/my_plugin/lib/active_shipping/ext/carriers/ups.rb
In /active_shipping I have file named extensions.rb in which i have:
require 'active_shipping' require_relative 'ext/carriers' require_relative 'ext/carriers/ups' It deals with loading everything properly (I suppose basing on regular_method beheaviour from first chunk of code in my question).
I try to invoke process_request in one of my Controllers. This part is little tricky, beacuse i'm using sth like this:
MyModel.courier_service.process_request(parameters)
where courier_service, in this case holds the ActiveMerchant::Shipping::UPS class.
I'm still a newbie in Ruby and don't know what sort of details i should provide.