2
類
的實例方法有一個在下面的代碼紅寶石:使用模塊包括
initshared.rb
module InitShared
def init_shared
@shared_obj = "foobar"
end
end
myclass.rb
class MyClass
def initialize()
end
def init
file_name = Dir.pwd+"/initshared.rb"
if File.file?(file_name)
require file_name
include InitShared
if self.respond_to?'init_shared'
init_shared
puts @shared_obj
end
end
end
end
的,因爲裏面的方法其包括InitShared不到風度的工作。
我想檢查文件,然後包含模塊,然後訪問該模塊中的變量。
你不需要一個空的`initialize`方法。 – 2011-02-09 22:15:59