From: nobu.nokada@... Date: 2004-10-04T09:20:03+09:00 Subject: Re: Kernel#eval taking a block 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. -- Nobu Nakada