EDIT: forgot to include information about my environment ... Win7x64, RubyInstaller Ruby v1.9.1-p378
EDIT 2: Just updated to version 1.1.1, patch 429 and still getting the same error.
Edit 3: the same code works in Ruby v1.8.7, patch 249, works fine. therefore it is v1.9.1 which broke it, apparently.
I'm new to using ERB, and the samples I could find were ... ummm ... less than useful ... playing with ERB for about an hour, I got some basic examples that work (finally) but I have no idea why this does not work ...
require 'ostruct' require 'erb' data = {:bar => "bar"} vars = OpenStruct.new(data) template = "foo " erb = ERB.new(template) vars_binding = vars.send(:binding) puts erb.result(vars_binding)
this code causes the following error:
irb (main): 007: 0> puts erb.result (vars_binding)
NameError: undefined local variable or method `bar 'for main: Object
from (erb): 1
from C: /Ruby/v1.9.1/lib/ruby/1.9.1/erb.rb: 753: in `eval '
from C: /Ruby/v1.9.1/lib/ruby/1.9.1/erb.rb: 753: in `result '
from (irb): 7
from C: /Ruby/v1.9.1/bin/irb: 12: in ``
why does he look at the main:Object binding? I told him to use binding from OpenStruct by going to vars_binding
can someone fill me with why it doesn't work and help me make it work?
ruby binding nameerror erb
Derick Bailey Jul 14 2018-10-14T00: 00Z
source share