From: Chad Perrin Date: 2006-08-02T06:40:56+09:00 Subject: Re: I thought this was the one that worked? On Wed, Aug 02, 2006 at 06:33:33AM +0900, Chad Perrin wrote: > On Wed, Aug 02, 2006 at 06:00:07AM +0900, ara.t.howard@noaa.gov wrote: > > On Wed, 2 Aug 2006, Chad Perrin wrote: > > > > >>it's not that there is no 'a', it's that there is no enclosing scope. the > > >>beginning of the 'def' introduces a new scope that is not 'contained' by > > >>the > > >>previous one. this is basic ruby. > > > > > >. . . > > > > > >What does that have to do with anything? > > > > because in the original code > > > > a = 42 > > > > def m > > puts a > > end > > > > 'a' will only be lexically scoped - and throw and error of course. the > > previous def of 'a' is totally superfluous - i was just pointing out that > > the > > failure of ruby to find 'a' is going to be a failure of lexical scoping > > rules > > because there is no enclosing scope (well nothing named in it yet) where an > > 'a' is defined. > > Ahh, I see where you were going. You were demonstrating that the "a" in > the scope of "m" is separate from the "a" outside of it, but didn't > really explicitly state that. I have a tendency to forget that def > creates a "new top level" scope, and need reminders. gsub /state/, 'explain' I apologize for any confusion my imprecise phrasing may have caused. > > I'm relieved to discover that Ruby isn't defaulting to dynamic scope in > the previous example after all. Thanks for the explanation. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "Real ugliness is not harsh-looking syntax, but having to build programs out of the wrong concepts." - Paul Graham