I have the following code in an ERB template:
<% ['foo', 'bar'].each do |var| %>
<%= previous %>
<% previous = "#{var}" %>
<% end %>
I would expect it to output foo, but it outputs nothing, previous is always nil. previous is not defined outside the loop, the first assignment happens after the end of the first loop.
This is how I'm rendering the template:
f.write ERB.new(File.read(node)).result(namespace.instance_eval { binding })
What am I doing wrong?