From: Intransition Date: 2011-11-15T01:37:38+09:00 Subject: Re: Binding#with ------=_Part_932_29786049.1321288653687 Content-Type: multipart/alternative; boundary="----=_Part_933_4604775.1321288653687" ------=_Part_933_4604775.1321288653687 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Sunday, November 13, 2011 10:16:37 PM UTC-5, Josh Cheek wrote: > > Note I had to explicitly define this in Binding to avoid the private method > invocation. > Sorry, I should have clarified that. Yes, that is the intent. > > 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 > > > > > Note that this didn't work for me unless I passed a hash to Binding#with, > because otherwise the syntax it generates looks like `lambda{ |,&yields| > binding }` which is a syntax error > Good point, thanks. ------=_Part_933_4604775.1321288653687 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sunday, November 13, 2011 10:16:37 PM UTC-5, Josh Cheek wrote:

Note I had to explicitly define this = in Binding to avoid the private method
invocation.

= Sorry, I should have clarified that. Yes, that is the intent.
&nb= sp;

> Now, it t= here a way to add a "yield" to the binding? I tried:
>
>  = def with(_local_variables, &_yields)
>     eval("lambd= a{ |#{_local_variables.keys.join(',')},&yields| binding
> }"= ).call(*_local_variables.values, &_yields)
>   end
&= gt;
>     b =3D binding.with{ |x| x+x}
>    = ; b.eval('yields[1]')  #=3D> 2
>
>
Note that this di= dn't work for me unless I passed a hash to Binding#with,
because otherwi= se the syntax it generates looks like `lambda{ |,&yields|
binding }`= which is a syntax error

Good point, thanks.


<= /p>

------=_Part_933_4604775.1321288653687-- ------=_Part_932_29786049.1321288653687--