Method: Chef::Decorator#method_missing

Defined in:
lib/chef/decorator.rb

#method_missing(m, *args, &block) ⇒ Object

this is the ruby 2.2/2.3 implementation of Delegator#method_missing() with adding the define_singleton_method call and @defined_methods tracking



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef/decorator.rb', line 52

def method_missing(m, *args, &block)
  r = true
  target = __getobj__ { r = false }

  if r && target.respond_to?(m)
    # these next 4 lines are the patched code
    define_singleton_method(m) do |*args, &block|
      target.__send__(m, *args, &block)
    end
    @__defined_methods__.push(m)
    target.__send__(m, *args, &block)
  elsif ::Kernel.respond_to?(m, true)
    ::Kernel.instance_method(m).bind(self).call(*args, &block)
  else
    super(m, *args, &block)
  end
end