From: Stefan Kaes Date: 2005-03-16T14:15:30+09:00 Subject: Re: eval/binding question 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. > That's not true. ERB::Defmethod does not work this way. And Rails uses the less efficient method, which I wanted to improve on (and did). And I wanted the local varaiable solution mainly for backwards compatibility with rendering partials in Rails. But the question about eval/binding semantics was posted to this list because I thought (and still think) that the semantics of eval is not what it should be.