Ruby. How to know which class instance method is defined?

162 views Asked by At

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?

1

There are 1 answers

8
Marek Lipka On BEST ANSWER

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.