I am looking into catching every method that is defined on a base class, looking up what file it is defined in, and then doing some logic based on that.
I currently have:
# Defined in some file
class Subclass < Base
def foo
end
end
class Base
self.method_added(method)
# self is a given subclass (Subclass)
# This doesn't work. :(
self.method(method).source_location
end
end
What I’d like to be able to do is find out the source location of that method.
I could do something like:
self.new.method(source).source_location
But don’t think I should be having to instantiate anything to get this to work.
Any ideas?
You can use method Module#instance_method to get instance method of your class: