是否有我的L
常量?模塊類<< self constants
module M
class Z
class << self
L = "foo"
end
end
end
=> M::Z::L
=> NameError: uninitialized constant M::Z::L
=> M::Z.constants
=> []
module B
class N
X = "bar"
end
end
=> B::N::X
=> "bar"
=> B::N.constants
=> [:X]
我讀this但我不明白。
[常量在類中的自身塊](http://stackoverflow.com/questions/2281057/constant-in-class-self-block) – toro2k
@ toro2k是的我看到了,但這是一個骯髒的黑客。 –