have alook at the book Code Generation in Action. Shows how to use Ruby & erb to generate all sorts of code. http://www.manning.com/books/herrington