I'm playing around with erb, so I fully understand what I'm documenting. I still have one nagging question...
<% ... %> vs. <%= ... %>
The Pickaxe II says the following about the first one:
"Insert the given Ruby code at this point in the generated program. If it outputs anything, include the output in the result."
It's the last line that's confusing me. If I feed erb:
% a = 99
<%= a %> bottles of beer...
I get:
99 bottles of beer...
If I change that to:
% a = 99
<% a %> bottles of beer...
I get:
bottles of beer...
I can of course use:
% a = 99
<% print a %> bottles of beer...
to get back to:
99 bottles of beer...
But I'm skeptical about HOW that is actually happening. It looks like a happy accident that they just both go to STDIN to me, especially if I view the source:
_erbout = ''; a = 99
print a ; _erbout.concat " bottles of beer...\n"
_erbout
My a output doesn't really end up in _erbout, like the rest of the code. Because of that, I assume I would have trouble here if I was generating this programatically with ERB objects. Let's see:
% cat erb_test.txt
% a = 99
<% print a %> bottles of beer...
% ruby -r erb -e 'res = ERB.new(ARGF.read, 0, "%"); puts "Answer is:" + res.result' erb_test.txt
99Answer is: bottles of beer...
Yeah, that's ugly.
So, what the heck does "If it outputs anything, include the output in the result." really mean? I'm confused.
James Edward Gray II