| 1. |
What Is The Scope Of A Local Variable In Ruby? |
|
Answer» 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. 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. |
|