Ruby. How do I know which method of an instance of a class is defined?
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 to share