From: "Hal E. Fulton" Date: 2003-01-21T08:27:45+09:00 Subject: Re: Local variable scope ----- Original Message ----- From: "Phil Tomson" Newsgroups: comp.lang.ruby To: "ruby-talk ML" Sent: Monday, January 20, 2003 3:54 PM Subject: Re: Local variable scope > >You can do this in 1.7: > > > >module M > > foo = "bar" > > define_method :function do > > puts foo > > end > >end > >include M > > > >function # prints: bar > > This falls into the catagory of > one-of-those-1.8-features-I-didn't-know-about. > > So define_method can define a method that 'knows' about all of the > variables in the scope in which it is defined? Useful, but one needs to > be careful. Correct me if I'm wrong, but isn't this simply because the do/end block itself is able to "see" the variable foo? The body of an ordinary method, i.e., def/end, looks similar to a do/end block but isn't one. This starts my mind speculating about the two converging into one thing... but that would likely raise more issues than it resolves. And I certainly am not in the mood to think it through. :) Hal