我有一个模块和一个包含该模块的类。这些没有在相同的文件或相同的文件夹中定义。我希望模块得到这个类中定义的目录ruby模块是否可以获取定义包含该模块的类的文件的目录?
# ./modules/foo.rb
module Foo
def self.included(obj)
obj_dirname = # ??? what goes here?
puts "the class that included Foo was defined in this directory: #{obj_dirname}"
end
end
# ./bar.rb
class Bar
include Foo
end
我希望这个输出是:
the class that included Foo was defined in this directory: ../
这可能吗?如果是这样,怎么样?
谢谢!这对我来说是获得我想要的功能的好方法。我担心多文件问题。知道包括什么是我需要的。 :) – 2010-08-06 00:45:41