Ruby Variable Scope

From Techotopia
Revision as of 18:37, 15 November 2007 by Neil (Talk | contribs) (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...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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