"_erbout = ''
_erbout.concat \"This is plain text\\n\"\n_erbout.concat \"And the
time is \"
_erbout.concat(( Time.now ).to_s)
_erbout.concat \"\\n\"\n_erbout.concat \" it was true\\n\"\n
_erbout.concat \"\\n\"\n_erbout.concat \" it wasn't true\\n\"\n
Thanks so much, Steve. I think that I get the essence of how it
works. It does not seem that erb directly translates an input
document into an output stream. Rather, it appears that erb produces
a Ruby program that, when run, produces the output stream. Lines of
the input document that consist wholly of text (i.e., they do not
contain any '<%' beginning markers or '%>' ending markers) are passed
as an argument to a method called erbout.concat which adds the line to
the output stream when the program is run. Thus, the intermediate
program contains a series of calls to erbout.concat (one for each text
line). Thus, if the input document contains no lines which include
beginning or ending markers, the intermediate program consists
exclusively of a series of calls to the erbout.concat method (one for
each line of input) with the relevant line passed as an argument to
the method. If such a program is run, it simply outputs the original
Now, let's see what happens when <% %> and <%= >%> markers are
introduced into the document. First of all, any such content is
treated as being placed on a separate line. So, if we we had:
The quick brown <% fox %> jumped over the lazy dog.
That would be treated as being:
The quick brown
<% fox %>
jumped over the lazy dog
The 'The quick brown' and 'jumped over the lazy dog' are now just
plain lines of text and as such they are treated accordingly by each
being passed as an argument to a call to the erbout.concat method.
What do we do with <% fox %>? Pretty much nothing. We through away
the beginning and ending markers and leave simply 'fox'. 'fox' is now
a fragment of Ruby code which will be run along with the other lines
of code, e.g., calls to erbout.concat when the program is run.
That only leaves us with figuring out how content within <%= and %>
markers is treated. That's pretty easy. The enclosed content is
evaluated as a Ruby statement and the output is treated as a line of
text which is passed as an argument to a separate call to
I think that's basically it. I feel much better now. I welcome any
comments on my analysis.
Thanks to all who contributed.
P.S. Colin, I didn't mean to ignore you; but, I didn't really see
anything in the Getting Started Guide that would help me with this
issue. Thanks for the input though.
jumped over the lazy dog