I'm learning ruby template and looking at the example provided by ruby documentation.
require 'erb'
x = 42
template = ERB.new <<-EOF
The value of x is: <%= x %>
EOF
puts template.result(binding)
When I change the example by doing something like this:
require 'erb'
x = 42
template = ERB.new <<-EOF
The value of x is: <%= x %>
The value of y is <%= y %>
EOF
puts template.result(binding)
I was hoping the template will become something like this:
The value of x is: 42
The value of y is <%= y %>
It gives me the error:
Error: undefined local variable or method `y' for main:Object (NameError)
Looks like we need to pass all the values for all the variable substitutions in the template.
Question: I'm just wondering if it is possible that we can have two variable substitutions in the template but only pass one value into the template when binding the data?
defined?(y).