34,333
edits
Changes
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>
== 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>


