:: Home     :: Add Questions
Register   |   Login
 

Question :: What is the scope of a local variable in Ruby?

Post Answer

Tags

ruby

Answers to ""

 

A new scope for a local variable is introduced in the toplevel, a class (module) definition, a method defintion. In a procedure block a new scope is introduced but you can access to a local variable outside the block. The scope in a block is special because a local variable should be localized in Thread and Proc objects. while, until, and for are control structures and the scope is shared with the outside of these structures. loop is a method and the appended block introduces a new scope.

Related Questions

::Top Tags::
 
 
Copyright 2007, Megasolutions Ltd