From: Stefan Lang Date: 2008-11-01T05:09:13+09:00 Subject: Re: How to access to local variables in enclosing scopes? 2008/10/31 Yuh-Ruey Chen : > Well then just wrap that example in another function: > > def scope() > a = 20 > def foo(): > a = 10 > def bar(): > print a # prints 10 > bar() > foo() > print a # prints 20 > scope() FWIW, Ruby doesn't have nested procedures like that. > I am trying to understand Ruby with some metaprogramming practice. But > I still feel that this is a really backwards step in language design. > > It's like telling me I should use GOTO in original BASIC instead of > trying to bend the language to simulate while loops. Would any sane > modern programmer do that? I don't think it's a good analogy. Ruby is more oriented towards little objects and message passing than Pascal-like nested procedures. I'm sure we could work out an elegant solution to some higher level goal than "accessing local variables", especially when it comes to metaprogramming. Stefan