I would personally go for something like this (based on OP's comment):
module ClassMethods
end
class Object
def extend_with_path(mod, filename)
p filename
self.extend(mod)
end
end
class Foo
extend_with_path ClassMethods, __FILE__
end
Assuming you have internal knowledge of the base
class, you could try something like this:
module ClassMethods
def self.extended(base)
p base.new.method(:superfluous_method).source_location
end
end
class Foo
def superfluous_method
end
extend ClassMethods
end
PS: I am aware this is a giant hack and not very nice, I would be curious to know if there are better ways of doing something like this.