I got this question from this discussion. A method call like object.m
does not always mean the class of "object" has a "m" method, just like the find method to a Array object is not directly originated from Array object, but from the mixed-in Enumerable module. My question is, given a method, how can we determine the class from which the method originated?
Any class/object method is an object in Ruby, and has some methods of it's own.
So you can do this:
[].method(:count).inspect
=> "#<Method: Array#count>"
[].method(:detect).inspect
=> "#<Method: Array(Enumerable)#detect>"
Quick bit of RegEx and you're done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With