Parsing ERB
suggest changerequire "erb"
input = <<~HEREDOC
<ul>
<% (0..10).each do |i| %>
<%# This is a comment %>
<li><%= i %> is <%= i.even? ? "even" : "odd" %>.</li>
<% end %>
</ul>
HEREDOC
parser = ERB.new(input)
print parser.result
<% %> runs Ruby and writes nothing. <%= %> inserts the value. <%# %> is a comment. The loop prints one <li> for each integer from 0 through 10.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents