From: Intransition Date: 2011-11-14T11:30:33+09:00 Subject: Binding#with ------=_Part_268_26888015.1321237829355 Content-Type: multipart/alternative; boundary="----=_Part_269_21242482.1321237829356" ------=_Part_269_21242482.1321237829356 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Binding#with def with(_local_variables) eval("Proc.new{ |#{_local_variables.keys.join(',')}| binding }").call(*_local_variables.values) end Try it: b = binding.with(:a=>1) b.eval('a') #=> 1 Now, it there a way to add a "yield" to the binding? I tried: def with(_local_variables, &_yields) eval("lambda{ |#{_local_variables.keys.join(',')},&yields| binding }").call(*_local_variables.values, &_yields) end b = binding.with{ |x| x+x} b.eval('yields[1]') #=> 2 but b.eval('yield(1)') #=> Error ------=_Part_269_21242482.1321237829356 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Binding#with

    def with(_local_va= riables)
      eval("Proc.new{ |#{_local_variables= .keys.join(',')}| binding }").call(*_local_variables.values)
&nbs= p;   end

Try it:

&nb= sp;   b =3D binding.with(:a=3D>1)
    b.eval('a= ')  #=3D> 1

Now, it there a way to add= a "yield" to the binding? I tried:

  de= f with(_local_variables, &_yields)
    eval("lambda= { |#{_local_variables.keys.join(',')},&yields| binding }").call(*_local= _variables.values, &_yields)
  end

<= /div>
&nb= sp;   b =3D binding.with{ |x| x+x}
    b.eval('yields[1]')  #= =3D> 2

but




------=_Part_269_21242482.1321237829356-- ------=_Part_268_26888015.1321237829355--