From: Joe Swatosh Date: 2015-03-13T22:40:59-07:00 Subject: [ruby-core:68520] Possible regression in 2.1 and 2.2 in binding when combined with delegate? --001a1132f91cd4ec870511390fc1 Content-Type: text/plain; charset=UTF-8 # The following code require 'delegate' require 'erb' class Example < SimpleDelegator def generate() template = "config = <%= config %>\n\n" puts ERB.new(template).result(create_bindable_context(self)) end def create_bindable_context(config) binding end end C = Struct.new(:a,:b) Example.new(C.new(:alpha, :beta)).generate ####################################################################### # Results in ruby 1.8.7 (2011-12-28 patchlevel 357) [i386-mingw32] config = # ruby 1.9.3p551 (2014-11-13) [i386-mingw32] config = # ruby 2.0.0p598 (2014-11-13) [i386-mingw32] config = # ruby 2.1.5p273 (2014-11-13 revision 48405) [i386-mingw32] (erb):1:in `method_missing': undefined local variable or method `config' for # (NameError) from C:/Ruby/ruby-2.1.5-i386-mingw32/lib/ruby/2.1.0/erb.rb:850:in `eval' from C:/Ruby/ruby-2.1.5-i386-mingw32/lib/ruby/2.1.0/erb.rb:850:in `result' from demo.rb:7:in `generate' from demo.rb:16:in `
' ruby 2.2.1p85 (2015-02-26 revision 49769) [i386-mingw32] (erb):1:in `method_missing': undefined local variable or method `config' for # (NameError) from C:/Ruby/ruby-2.2.1-i386-mingw32/lib/ruby/2.2.0/erb.rb:863:in `eval' from C:/Ruby/ruby-2.2.1-i386-mingw32/lib/ruby/2.2.0/erb.rb:863:in `result' from demo.rb:7:in `generate' from demo.rb:16:in `
' ####################################################################### Regression or yet another thing I don't understand? Thanks -- Joe --001a1132f91cd4ec870511390fc1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
# The following code=C2=A0

r= equire 'delegate'
require 'erb'

class Example < SimpleDelegator
=C2=A0 def generate()<= /div>
template = =3D "config =3D <%=3D config %>\n\n"
=C2=A0 =C2= =A0 puts ERB.new(template).result(create_bindable_context(self))
= =C2=A0 end
=C2=A0
=C2=A0 def create_bindable_context(co= nfig)
=C2=A0 =C2=A0 binding
=C2=A0 end
end

C =3D Struct.new(:a,:b)
Example.new(C.new(= :alpha, :beta)).generate

#########################= ##############################################
# Results in
=

ruby 1.8.7 (2011-12-28 patchlevel 357) [i386-mingw32]

config =3D #<struct C a=3D:alpha, b=3D:beta><= /div>


ruby 1.9.3p551 (2014-11-13) [i386-m= ingw32]

config =3D #<struct C a=3D:alpha, b=3D:= beta>


ruby 2.0.0p598 (2014-11-13= ) [i386-mingw32]

config =3D #<struct C a=3D:alp= ha, b=3D:beta>


ruby 2.1.5p273 (2= 014-11-13 revision 48405) [i386-mingw32]

(erb):1:i= n `method_missing': undefined local variable or method `config' for= #<struct C a=3D:alpha, b=3D:beta> (NameError)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 from C:/Ruby/ruby-2.1.5-i386-mingw32/lib/ruby/2.1.0/erb.r= b:850:in `eval'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 from C:/Ruby/ruby= -2.1.5-i386-mingw32/lib/ruby/2.1.0/erb.rb:850:in `result'
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 from demo.rb:7:in `generate'
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 from demo.rb:16:in `<main>'

ruby 2.2.1p85 (2015-02-26 revision 49769) [i386-mingw32]

(erb):1:in `method_missing': undefined local variable o= r method `config' for #<struct C a=3D:alpha, b=3D:beta> (NameErro= r)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 from C:/Ruby/ruby-2.2.1-i386-mingw= 32/lib/ruby/2.2.0/erb.rb:863:in `eval'
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 from C:/Ruby/ruby-2.2.1-i386-mingw32/lib/ruby/2.2.0/erb.rb:863:in `r= esult'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 from demo.rb:7:in `generat= e'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 from demo.rb:16:in `<main&g= t;'

##########################################= #############################

Regression or yet an= other thing I don't understand?

Thanks=C2=A0
--
Joe

--001a1132f91cd4ec870511390fc1--