Nested ERB block
require 'erb'
template = %q{
<% if problems.empty? %>
it is true
<% else %>
Here is else
<% problems.each do |problem, line| %>
* <%= problem %> on line <%= line %>
<% end %>
<% end %>}.gsub(/^\s+/, '')
template = ERB.new(template, nil, '<>')
problems = [["Use of is_a? ", 23],
["eval() is dangerous", 44]]
template.run(binding)
Related examples in the same category