Main Content

Constants in Ruby

Archive - Originally posted on "The Horse's Mouth" - 2010-02-01 21:54:45 - Graham Ellis

If you want to have a read only variable in Ruby, start its name with a capital letter (and you may like to go with a convention of using capitals right through the variable name).

Note that a Ruby constant - a name starting with a capital - hasa global scope, just like a variable name that starts with a $

There's an example [here] from today's Learning to Program in Ruby Training Course.