为什么c.f()
下面不起作用b.f()
?我想使用class A::C
- 方式来声明一个嵌套类以避免太多的缩进。
class A
CONSTANT = 1
end
class A
class B
p self # => A::B
def f
print CONSTANT, "\n"
end
end
end
class A::C
p self # => A::C
def f
print CONSTANT, "\n"
end
end
b = A::B.new
b.f() # => 1
c = A::C.new
c.f() # => `f': uninitialized constant A::C::CONSTANT (NameError)