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' 메소드는 필요 없습니다. –