Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不断收到此错误:未初始化的常量 A::MYCONST 我的代码看起来像
class A MYCONST = "myconst" end class B < A TEST = A::MYCONST end
p RUBY_VERSION class A MYCONST = "myconst" end class B < A p TEST = A::MYCONST p defined? TEST end
输出:
"2.0.0" "myconst" "constant"
解释器抱怨是因为它期望B::A::MYCONST.
B::A::MYCONST
在类 B 中,在 line2 中定义的 const 可以由 any::A::MYCONST或 just引用MYCONST。
::A::MYCONST
MYCONST