I have long known that “constants” in Ruby (that is, variable names that are uppercase) are not really constant. Like other programming languages, an object reference is the only thing stored in a variable / constant. (Sidebar: Ruby has the ability to “freeze” objects referenced by objects that, as far as I know, are not an ability offered in many other languages.)
So here is my question: when you reassign a value to a constant, you get a warning like this:
>> FOO = 'bar'
=> "bar"
>> FOO = 'baz'
(irb):2: warning: already initialized constant FOO
=> "baz"
Is there a way to get Ruby to throw an exception instead of printing a warning? It is difficult to understand why reassignments sometimes occur.
source
share