当我尝试将 Singleton 模块包含在本身存在于模块中的类中时,它不起作用。这是一个例子:
require 'singleton'
module SomeModule
end
class SomeModule::SomeClass
include Singleton
def initialize
@some_variable = 1
end
def output
puts @some_variable
end
end
SomeClass.instance.output
我得到的错误是:
未初始化的常量 Object::SomeClass (NameError)
我不确定如何告诉 Singleton 模块查找SomeModule::SomeClass
notObject::SomeClass