Ruby. How do I know which method of an instance of a class is defined?

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

How can I determine which class in the hierarchy is overriding it?

+3


source to share


1 answer


You can use a method UnboundMethod#owner

to check where this 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 a module (which is later placed in the class hierarchy somewhere), owner

this module will be returned.

+6


source







All Articles