What is the scope of a local variable in Ruby?

Questions by Robert   answers by Robert

Showing Answers 1 - 0 of 0 Answers

natchiar

  • Aug 17th, 2007
 

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.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions