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 .
Some other articles
R110 - Special Variables and Pseudo-Variables One line scripts - Awk, Perl and Ruby Reading and parsing a JSON object in Ruby Ruby - a teaching example showing many of the language features in short but useful program Object Oriented Ruby - new examples This article Variable scope - what is it, and how does it Ruby? Ruby to access web services Some Ruby programming examples from our course Variable types in Ruby Ruby - Totally Topical R103 - Basic Ruby Language Elements Where does Ruby load modules from, and how to load from current directory Ruby - the second rung of learning the language Learning to program - variables and constants BODMAS - the order a computer evaluates arithmetic expressions Ruby - standard operators are overloaded. Perl - they are not Sigils - the characters on the start of variable names in Perl, Ruby and Fortran Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. Comparing floating point numbers - a word of caution and a solution This article Variable scope - what is it, and how does it Ruby? Learning to program in Ruby - examples of the programming basics puts - opposite of chomp in Ruby