Changes

Jump to: navigation, search

Ruby Variable Scope

712 bytes added, 18:37, 15 November 2007
New page: Now that we have covered the basics of variables in Ruby the next task is to explain Ruby variable scope. == What is Variable Scope? == Scope defines where in a program a variable is acc...
Now that we have covered the basics of variables in Ruby the next task is to explain Ruby variable scope.

== What is Variable Scope? ==

Scope defines where in a program a variable is accessible. Ruby has four types of variable scope, ''local'', ''global'', ''instance'' and ''class'. Each variable type is declared by using a special character at the start of the variable name as outlined in the following table.

<table border="1"><tr><td><code>$</code> </td><td> a global variable </td></tr>
<tr><td>
<code>@</code> </td><td> An instance variable </td></tr>
<tr><td>
<code>[a-z]</code> or <code>_</code> </td><td>A local variable </td></tr>

<tr><td>
<code>[A-Z]</code> </td><td>A constant</td></tr></table>

Navigation menu