Thoughts on Coding

From a recent IM conversation with a good friend of mine:

Andrew Bloom
12:51 i hate working on shitty codebases
12:51 i wish i had time to do a major refactoring
Stephan Mokey
12:52 yeah, code is never done, it’s just due
12:52 we are artists

ERB templates of ERB templates

Recursion, every programmers favorite topic. Luckily that’s not what this is about, really. Today at work I was writing a Rails Generator that needed to created <a href=”http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/”>ERB</a> templates for views. It sounded pretty simple, but I hit one stumbling point. How do I make my template an ERB template that generates an ERB template of its own without interpreting all of the tags? After a bit of Googling I started to get discouraged. Then I remembered Rails already does some of this in places like the scaffold generator. I opened up the source and the templates and found an ERB tag I had never seen before <code><%%= do_something %></code>. There it was, the ‘%%’ will tell ERB to treat this as a tag for a future run. It will remove the second % and leave you with the output you expect.