0
我试图从父类访问不变,但得到错误无法访问不断从父类中的红宝石
NameError:未初始化不断CONSTS
这是我的代码 - 父类
module Abc
class Xyz
class A
class CONSTS
ONE = "1"
TWO = "2"
Three = "3"
end
end
end
end
这是子类
module Abc
class Xyz
class B < A
class << self
def print_const
get_const
end
private
def get_const
puts CONSTS::ONE
end
end
end
end
end
现在,当我尝试Abc时:Xyz :: B.print_const我得到了上述错误。
谁能告诉我我在哪里做错了?
downvoted使用小写模块和类名称。 – saihgala
@AshishSaihgal:纠正它 –