An ERB/bundler behaviour I don't understand

Yes, in a way.

Over at the Bundler slack, someone mentioned that the test in question fails with and without using Bundler. When I experimented a bit more with other Ruby versions … results where even more confusing to me.
By now, I assume that something, messed up my Ruby installation (a Gem? env. variable? Ruby related dot file?) — After entirely removing RVM, reinstalling it and building a new Ruby 3.0.2 from scratch, I also got the test failure in both situations.

Meanwhile, I thought about the problem I was trying to solve and came to the conclusion, that it may be better to fail badly when trying to replace an ERB template because the value is missing, rather than inserting some default value and be surprised about it later.

Also I reduce the code above to this:

require 'erb'

def render(template, configuration_data)
  ERB.new(template).result_with_hash(configuration_data)
end

That’s much easier to understand, compared to setting the default for a hash and then using instance_eval and binding.
Using result_with_hash is much simpler (and something I didn’t know about before).

3 Likes