为什么下面的例子有错误?
class ClassA
class ClassB
end
class ClassC
def test
ClassB.new
end
end
end
p ClassA::ClassC.new.test # => #<ClassA::ClassB:0x0000010103f860>
class ClassA
class ClassD
def test
ClassB.new
end
end
end
p ClassA::ClassD.new.test # => #<ClassA::ClassB:0x0000010103f010>
class ClassA::ClassE
def test
ClassB.new
end
end
p ClassA::ClassE.new.test # => NameError: uninitialized constant ClassA::ClassE::ClassB
是否有另一种创建方式ClassE
,而不是通过键入class ClassA; class ClassE
?