--Apple-Mail-1--502680050
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII; format=flowed

On 15 Mar 2005, at 19:55, Eric Hodel wrote:

> On 15 Mar 2005, at 08:17, Stefan Kaes wrote:
>
>> when using ERB one can compile a template into source, which can then 
>> be eval'ed using eval. Local variables for use in the template can be 
>> set up using the sort of eval given in my example. However, in this 
>> case the 'compiled' template code gets reparsed on each evaluation of 
>> the template code. I wanted to speed up this process by defining a 
>> function (eval "def fun; #{src}; end", aBinding), thereby pasring the 
>> code only once.
>
> ERb already does this for you.  See ERB::Defmethod.  Unfortunately, 
> there are no docs for it, but you can dig around in Rails to see how 
> it is used.

Ok, I lied.  ERB::DefMethod is both not used by Rails (does something 
else) but it is also unsuitable for the task.

Anyhow, as my penance, here's my implementation, I did use def_method, 
though:

http://segment7.net/projects/ruby/snippets/erb_cache.rb

-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04

--Apple-Mail-1--502680050
content-type: application/pgp-signature; x-mac-type=70674453;
	nameP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCN7qaMypVHHlsnwQRAusxAJ91YtmZxwzqnOCCwWNlVYvVJMv/DwCeL7X2
7Zps0NGBjewBXoZI9Cy3f54ai
-----END PGP SIGNATURE-----

--Apple-Mail-1--502680050--