Writing an assignment such as CONST = some_var will raise SyntaxError as Constant in ruby could not be reassigned.
But in some cases, I want to hold the current variable’s value in a constant and lock it there.
For example, when I initialize an instance from a class, I want to lock the passed in value within the instance. How should I do it the right way in ruby? (following is a illegal code in ruby trying to realize it, you get the idea)
class SomeClass
def initialize(status)
STATUS = status # it is illegal now
end
end
The Ruby constants are expected to preserve the same value, it’s a recommendation, not a must: