Hello guys,
I'm developing two Ruby gems, one is a framework, the other is an application. My main app's class inherits from a framework's class.
The class defined in the framework have some file loading methods that rely on __FILE__ so subclasses can load resources relative to their path.
What I want is for the subclasses to be able to use those methods defined in the parent without (basically) touching them. Is it possible?
The problem is with __FILE__, it doesn't change if the code is called from a subclass, so the loading resource methods are "stuck" in the frameworks directory, instead of trying to load from the app dirs.
I know I can redefine those methods in the subclass, but I wanted to take advantage of them being already defined in the parent.
I want the subclasses to refer to their own directory (where the subclass file is) using a method defined in the parent, that's the problem.
Or do I have to set the app directory by hand?
I'll try to make that clearer:
Is it possible to write a method like this:
# /home/usr/framework/parent.rb
class Parent
def show_my_path
puts File.dirname(__FILE__)
end
end
# /home/usr/app/app.rb
# require Parent
class App < Parent
end
App.new.show_my_path
# Can we have here /home/usr/app
# instead of /home/usr/framework ?
# What's the right way to do this?