From: Eric Mahurin Date: 2005-10-13T07:38:43+09:00 Subject: Re: Default argument values for blocks --- "Ara.T.Howard" wrote: > On Thu, 13 Oct 2005, Sean O'Halpin wrote: > > > On 10/12/05, Eric Mahurin wrote: > >> Or maybe if "eval" became a keyword like you mentioned > above > >> and it could also take a block, you could do this instead: > >> > >> b=1 > >> eval {|;b| > >> b=5 > >> p b # => 5 > >> } > >> p b # => 1 > > > > +1 > > > > Any chance of eval taking a block ~and~ a specific binding, > e.g. > > > > eval &block, binding > > > > (though this breaks current argument parsing rules). > > > > Sean > > eval(binding, &block) works. the eval(string) method just > needs to check it's > arg type. It doesn't need to check type. If there is a block, the optional arg would be a binding. Otherwise, the first arg is the eval string and the optional second arg is the binding. If this is possible, it would be good to be able to do this to a general Proc. But, if not you could still make the functionality with the above Kernel#eval: class Proc def rebind(binding) Proc.new { eval(binding,&self) } end end Of course you have the same problem that we have with instance_eval - you can't pass any args. Might as well think about making that work with eval too. __________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/