eg:
class Base
def self.inherited(subclass)
puts "New subclass: #{subclass}"
path_of_subclass = ????
end
end
Then in another file/class, it extends Base.
class X < Base
....
end
How would I get the path to the rb file of that subclass from the super class.
Use the
callermethod and parse it for the filename.inheritedis always called from the file that is defining the class.Consider the following:
a.rb:
b.rb:
Let’s run this: