Handling Constants in Ruby
Ruby is very open and flexible to change programming language as such you cannot 100% ensure that your constants won’t be change ever. However, Ruby constants do exist. You need to declare constants by capitalizing constant variables and assigning values to it.
MY_CONSTANT = 10
You can set constants throughout your project space and you can access them from outside classes and modules by specifying double column (::) in front of it.
class MyConstantClass
MY_CONSTANT = 10
end
Accessing constant from within the class will be possible by adding double column
MyConstantClass::MY_CONSTANT
You need to apply freeze to a constant in order to prevent this constants from being modified. This will ensure that your constant stays constant.