2013-01-02 20 views
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我得到了上述错误。

谁能告诉我我在哪里做错了?

+0

downvoted使用小写模块和类名称。 – saihgala

+0

@AshishSaihgal:纠正它 –

回答

0

尝试使用a::CONSTS:ONE或完整标识符::abc::xyz::a::CONSTS:ONE

+0

我知道,但为什么我无法访问父类中的常量派生?此外,我觉得它不是一个正确的方式来访问常量。 –