From: "David A. Black" Date: 2005-07-31T01:33:10+09:00 Subject: Re: make local var visible Hi -- On Sun, 31 Jul 2005, Trans wrote: > Hmm... I just ran into a problem with constant lookup (namely > class/module lookup). I wrote an autoloader, such that of > #const_missing it will try to find the class or module in a file and > require it. Unfortuately, for it to work I ALWAYS has to use '::' > before the class/module name. I know what the problem and how to fix > --I need to work upward through each namespace to see if it's there. > But that got me thinking about what botp has asked. > > First I wondered what this could be meaningful: > > foo = [ "a","b","c" ] > > def mfoo > ::foo.each do |f| > p f > end > > mfoo > > Then wondered too if variable lookup could proceed in a manner like > constant lookup. If you don't find it in the current scope, then try > the next one up, and so on. local -> instance -> class -> module > namespaces -> ... -> top/global. (hmm..That's how block scopes seem to > work too, now that I think of it.) > > I must be over looking something though, it seems too straight foward > ;-) That would essentially do away with the notion of a local variable. I think it's valuable to have them -- really quarantined "scratchpad" things that just don't overlap between scopes. Writing things that depend on local variable names from other scopes is pretty fragile. David -- David A. Black dblack@wobblini.net