views:

32

answers:

1

I have the parent class in /dir1/test1.rb then i have the child class in /dir2/test2.rb

the test1 class has a method that uses the "File.dirname(FILE)". BUT when i call this method from the test2, that inherent from test1 the dir is the dir1, insted the dir2, where the test2 is.

How to make it work?

A: 

the use of __FILE__ has to be in test2.rb

It's really that simple. How about this?

class Test2
  def self.here
    @here ||= File.dirname(__FILE__)
  end
end

Then in the method in test1 you call self.here

jshen
the problem is that im repeating too much, imagine i have 100 child classes, and then each one should have that here method... it hurts and is not DRY :S there is not a better solution?
Totty