From: Eric Mahurin Date: 2005-09-20T01:17:13+09:00 Subject: Re: help with tricky proc/binding issue --- Florian Gro� wrote: > Yukihiro Matsumoto wrote: > > > |i'm trying to be able to define a proc that can be called > in the context of > > |self, eg: > > | > > | block = lambda{ p 42 } > > | an_obj.instance_eval &block > > | > > |but which can also be called with arguments, for example > (imaginary ruby): > > > > I understand what you want. But I haven't come up with a > good name > > for the function yet. > > What about Proc#with_self() that will return a new proc > similar to the > current one, but with a changed self context? I've talked about this before, but the ability to return a new proc with local variables manipulated would also be nice: - Make "local" variables really local to the proc. Initialize these to the current values of the local variables in the previous binding. Effectively, this gives the proc its own local binding (at least for "local" variables). This could be done in conjunction with redefining self for the proc to. It would also be nice to be able to be able to do the same thing for blocks easily so that you could easily localize your "local" variables in your block. But, you could emulate that as long as you had a way to localize proc local variables: foo(&(lambda{...}.localize)) or if you could do it directly to a block you may have some syntax like this: foo {{...}} # double braces to represent localization But, that has some conflicts with hash. Not sure of a good syntax. The problem is we can't apply methods directly to blocks - you have to convert to Proc, apply the method, and convert back. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com