3

I want to know which class method_missing is defined. It is defined in Object.

How can I figure out which class along the hierarchy overrides it?

Zhang Kai Yu
  • 362
  • 2
  • 8

1 Answers1

6

You can use UnboundMethod#owner method to check where the method is implemented:

class A
  def method_missing(*args)
    # do something
  end
end
method = A.instance_method(:method_missing)
method.owner
# => A

Note: If the method is implemented in module (which is later mixed into the class hierarchy somewhere), owner will return this module.

Marek Lipka
  • 50,622
  • 7
  • 87
  • 91