Difference between revisions of "Ruby Variable Scope"
From Techotopia
(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...) |
(No difference)
|
Revision as of 18:37, 15 November 2007
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.
$ | a global variable |
@ | An instance variable |
[a-z] or _ | A local variable |
[A-Z] | A constant |


