
Polished Ruby Programming
By :

Ruby has constants, but unlike constants in most other languages, Ruby's constants are actually variables. It's not even an error in Ruby to reassign a constant; it only generates a warning. Say you try the following code:
A = 1 A = 2
Then you'll see it only generates two warnings:
# warning: already initialized constant A # warning: previous definition of A was here
At best, Ruby's constants should be considered only as a recommendation. That being said, not modifying a constant is a good recommendation. In general, you shouldn't modify constants unless you have to, especially constants that are in external code such as libraries.
You can think of a constant in Ruby as a variable type that can only be used by modules and classes, with different scope rules. As both modules and classes are objects, they can both have instance variables in addition to constants. When a class or module needs...