0
當我嘗試將Singleton模塊包含在本身存在於模塊中的類中時,它不起作用。這裏有一個例子:ruby NameError包含屬於另一個模塊的類中的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
,我得到的錯誤是:
未初始化的常量 對象:: SomeClass的(NameError)
我不知道如何告訴辛格爾頓模塊尋找SomeModule::SomeClass
不是Object::SomeClass
現在我明白了。猜猜這只是其中的一個。謝謝! – ZombieDev 2011-02-16 17:36:20