From: Intransition Date: 2011-11-13T07:17:39+09:00 Subject: Re: Advanced Ruby: Eval over multiple Bindings? ------=_Part_1437_18131298.1321136255790 Content-Type: multipart/alternative; boundary="----=_Part_1438_24940715.1321136255790" ------=_Part_1438_24940715.1321136255790 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Saturday, November 12, 2011 4:10:09 PM UTC-5, Quintus wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Am 12.11.2011 21:19, schrieb Intransition: > > Is there a way to "merge" the binding to do something like: > >=20 > > eval('a + b', binding1 + binding2) #=3D> 3 > > Not sure if that=E2=80=99s exactly what you want, but this works: > > binding1.eval("a + binding2.eval('b')") #=3D> 3 > > This is not 'merging' the two bindings, it rather opens the second > binding inside the first one. > My usecase is for template generation. For example ERB, it's render method= =20 takes *a* Binding. =20 > Regarding Binding#eval, is there a specific reason why it can=E2=80=99t t= ake a > block instead of a string, the same way e.g. Module#instance_eval does? > Actually I suggested that feature on ruby issue tracker and I believe the= =20 anwser given was YAGNI. If it were possible could it solve this? ------=_Part_1438_24940715.1321136255790 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Saturday, November 12, 2011 4:10:09 PM UTC-5, Quintus wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash= : SHA1

Am 12.11.2011 21:19, schrieb Intransition:
> Is there a way = to "merge" the binding to do something like:
>
> eval('a + b',= binding1 + binding2)  #=3D> 3

Not sure if that=E2=80=99s exa= ctly what you want, but this works:

  binding1.eval("a + binding= 2.eval('b')") #=3D> 3

This is not 'merging' the two bindings, it r= ather opens the second
binding inside the first one.


My usecase is for template generation. For example ERB, it= 's render method takes a Binding.

 

Regarding Binding#eval, = is there a specific reason why it can=E2=80=99t take a
block instead of = a string, the same way e.g. Module#instance_eval does?


Actually I suggested that feature on ruby issue tracker and= I believe the anwser given was YAGNI.

If it were = possible could it solve this?


<= p>

------=_Part_1438_24940715.1321136255790-- ------=_Part_1437_18131298.1321136255790--