On 5/21/07, ara.t.howard <ara.t.howard / gmail.com> wrote: > > On May 19, 2007, at 9:58 AM, Matt Gretton wrote: > > > Hello all, > > > > What techniques do people generally use to create files and write ruby > > code to them? ... > > For example, I have heard that ruby on rails dynamically creates files > > containing ruby code. This behavior seems pretty common to various > > ruby > > projects, for example I know rails creates ruby source code > > dynamically. > > there is an entire book on the topic > > http://www.manning.com/herrington/ > In my experience, it's rare to approach this in Ruby by writing ruby code to files. Rails uses metaprogramming techniques to dynamically generate and modify classes at run-time, no need to do this by writing and reading source files. It also uses other techiques to generate other artifacts like html, such as using eruby which allows embedded ruby code to produce part or all of the content dynamically again at runtime. This is how I've usually seen things like this done in Ruby. I'm not familiar with the book Ara recommended, but a quick scan of the on-line contents and sample chapter seems to indicate that it's really about generating code for languages other than Ruby, although it does seem to use Ruby as the language for writing code generators. It seems to me that the dynamic runtime generation/expansion allowed by a dynamic language like Ruby provides the advantages of code generation and avoids drawbacks like how to approach re-generating modified code, since the generated code never exists as a file to be modified. I'd recommend that the OP do a google search on ruby metaprogramming. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/