T. Onoma
10/4/2004 2:23:00 PM
On Sunday 03 October 2004 08:20 pm, nobu.nokada@softhome.net wrote:
> Hi,
>
> At Sun, 3 Oct 2004 10:25:37 +0900,
>
> trans. (T. Onoma) wrote in [ruby-talk:114646]:
> > Is there a reason Kernel#eval won't take a block? I wrote this to
> > overcome:
> >
> > # Evaluate a Ruby source code string (or block) in the binding context
> > def evalb( str=nil, binding=nil, &blk )
> > if block_given?
> > Kernel.eval( "proc {|slf, blk| slf.instance_eval(&blk)}",
> > binding ).call( binding, blk )
> > elsif str
> > Kernel.eval( str, binding )
> > end
> > end
>
> It's evaluated in the Binding/Proc's context, but not in the
> context where it was created. I.E., it is equivalent to
>
> binding.instance_eval(&blk)
>
> except that variables `slf' and `blk' will be altered if they
> exist in the context of `binding'.
>
> Seems less meaningful.
Crud. I see. You are ( as always ;) quite correct. Is there anyway to
overcome? Back to the original question: why Kernel#eval can't take a block?
Thanks,
T.