In Ruby, is there a way to \'override\' a constant in a subclass in such a way that calling an inherited method from the subclass results in that method using the new consta
You can refer to a constant like this in the parent class:
For a instance method: self.class::CONST
For a self method: self::CONST
class SuperClass
CONST = "Hello, world!"
def print_const
puts self.class::CONST
end
def self.print_const
puts self::CONST
end
end
class SubClass < SuperClass
CONST = "Hello, Bob!"
end
SubClass.new.print_const #=> "Hello, Bob!"
SubClass.print_const #=> "Hello, Bob!"