From: "David A. Black" Date: 2003-11-27T00:25:30+09:00 Subject: Re: Controlled block variables Hi -- On Wed, 26 Nov 2003, Dan Doel wrote: > I actually have wondered in the past why there isn't an #eval that takes > a proc (other than as a binding). > > There's #instance_eval and #module_eval/#class_eval for replacing the > object scope of a Proc, but > there's no way you can do this: > > def foo > a = 4 > b = 5 > > proc { p a; p b } > end > > def bar(p) > a = 7 > b = 8 > > eval p > end > > bar(foo) > > and get 7 and 8 printed. I realize that Proc objects are closures, but > since they're also representations > of sections of code, it would be interesting to be able to switch them > to dynamic scoping for all the > benefits and problems that causes, and using #eval seems like a fairly > clean way of denoting that. I can see what you're getting at, but I don't agree that it's clean, because it involves so much magic; in particular, both the program and the programmer would have to know what the names of the variables from the proc's creation context were, which means things get very unencapsulated and very coupled. David -- David A. Black dblack@wobblini.net