How to use an overridden constant in an inheritanced class

后端 未结 4 953
深忆病人
深忆病人 2021-02-02 07:27

given this code:

class A
  CONST = \'A\'

  def initialize
    puts CONST
  end
end

class B < A
  CONST = \'B\'
end

A.new # => \'A\'
B.new # => \'A\'
         


        
4条回答
  •  感情败类
    2021-02-02 07:50

    In case anyone finds this and is using module extension instead, just use

    self::CONST

提交回复
热议问题