Changes

Understanding Ruby Variables

812 bytes added, 21:07, 14 November 2007
no edit summary
Variables are essentially a way to store a value and assigning a name to that value. Variables take various forms ranging from integers to strings of characters.In this chapter we will take a look at how variables are declared and converted. We will also look at the much simpler area of Ruby constants. == Ruby Constants == A Ruby constant is used to store a value for the duration of a Ruby program's execution. Constants are declared by beginning the variable name with a capital letter (a common convention for declaring constants is to use uppercase letters for the entire name). For example: <pre>MYCONSTANT = "hello"=> "hello"</pre> Unlike other programming languages, Ruby actually allows the value assigned to a constant to be changed after it has been created. The Ruby interpreter will, however, issue a warning - even though it allows the change: <pre>MYCONSTANT = "hello2"(irb):34: warning: already initialized constant Myconstant=> "hello2"</pre>
== Ruby and Variable Dynamic Typing ==