Re: ERB as a macro pre-processor?

From: Rich M. [mailto:[email protected]]

One possibility that occurred to me is to use ERB as a macro
pre-processor.
[snip]
eval template.result(binding)

Out of curiosity, would there be any benefit to writing the code to a
(temporary) file and having Ruby require that file, instead of eval’ing
the resulting string?

Obviously the file version has the downside of using system resources
and delay for writing/reading the file. However, I have been tought to
have such an aversion to ‘eval’ in various languages that some part of
me wonders if there would be a good reason to let Ruby do things in a
‘standard’ way rather than using eval.

At 1:39 AM +0900 10/12/06, Gavin K. wrote:

… I have been tought to have such an aversion to ‘eval’
in various languages that some part of me wonders if
there would be a good reason to let Ruby do things in a
‘standard’ way rather than using eval.

I think that the basic concern with eval is that spurious
code might be brought into the program. “require” has the
same problem, if the file has been auto-generated.

-r

http://www.cfcl.com/rdm Rich M.
http://www.cfcl.com/rdm/resume [email protected]
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs