# Re: ERB as a macro pre-processor?

**URL:** <https://www.ruby-forum.com/t/re-erb-as-a-macro-pre-processor/71822>\
**Category:** Ruby\
**Created:** [October 11, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/re-erb-as-a-macro-pre-processor/71822 "2006-10-11T18:41:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 11, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/re-erb-as-a-macro-pre-processor/71822/1 "2006-10-11T18:41:09Z")

</div>

From: Rich M. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

> 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.

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 11, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/re-erb-as-a-macro-pre-processor/71822/2 "2006-10-11T18:55:11Z")

</div>

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](http://www.cfcl.com/rdm) Rich M.  
[http://www.cfcl.com/rdm/resume](http://www.cfcl.com/rdm/resume) removed\_email\_address@domain.invalid  
[http://www.cfcl.com/rdm/weblog](http://www.cfcl.com/rdm/weblog) +1 650-873-7841

Technical editing and writing, programming, and web development
