From: Josh Cheek Date: 2012-07-26T06:56:00+09:00 Subject: Re: String interpolation / hash of local variables --f46d04339cae230dac04c5ae8be0 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jul 25, 2012 at 3:14 PM, Sam Duncan wrote: > What about simply > > > irb > 1.9.3p125 :001 > template = "
%{example}
\n
%** > {foobar}
" > => "
%{example}
\n
%**{foobar}
" > 1.9.3p125 :002 > arr = [] > => [] > 1.9.3p125 :003 > magical_hash_with_local_**variables = {} > => {} > 1.9.3p125 :004 > magical_hash_with_local_**variables[:example] = "magical" > => "magical" > 1.9.3p125 :005 > magical_hash_with_local_**variables[:foobar] = "hash" > => "hash" > 1.9.3p125 :006 > arr.push template % magical_hash_with_local_**variables > => ["
magical
\n
**hash
"] > > No eval. No external dependencies. In your loop you just populate your > magical hash anew. > > Nice! didn't know you could do that. --f46d04339cae230dac04c5ae8be0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, Jul 25, 2012 at 3:14 PM, Sam Duncan <sduncan@wetafx.co.nz= > wrote:
What about simply

> irb
1.9.3p125 :001 > template =3D "<div>%{example}</div>\n&= lt;div>%{foobar}</div>"
=A0=3D> "<div>%{example}</div>\n<div>%{foo= bar}</div>"
1.9.3p125 :002 > arr =3D []
=A0=3D> []
1.9.3p125 :003 > magical_hash_with_local_variables =3D {}
=A0=3D> {}
1.9.3p125 :004 > magical_hash_with_local_variables[:example] =3D = "magical"
=A0=3D> "magical"
1.9.3p125 :005 > magical_hash_with_local_variables[:foobar] =3D &= quot;hash"
=A0=3D> "hash"
1.9.3p125 :006 > arr.push template % magical_hash_with_local_vari= ables
=A0=3D> ["<div>magical</div>\n<div>hash<= ;/div>"]

No eval. No external dependencies. In your loop you just populate your magi= cal hash anew.


Nice! didn't k= now you could do that.
--f46d04339cae230dac04c5ae8be0--