[#68478] Looking for MRI projects for Ruby Google Summer of Code 2015 — Tony Arcieri <bascule@...>

Hi ruby-core,

10 messages 2015/03/10

[ruby-core:68520] Possible regression in 2.1 and 2.2 in binding when combined with delegate?

From: Joe Swatosh <joe.swatosh@...>
Date: 2015-03-14 05:40:59 UTC
List: ruby-core #68520
# 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 = #<struct C a=:alpha, b=:beta>


ruby 1.9.3p551 (2014-11-13) [i386-mingw32]

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


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

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


ruby 2.1.5p273 (2014-11-13 revision 48405) [i386-mingw32]

(erb):1:in `method_missing': undefined local variable or method `config'
for #<struct C a=:alpha, b=:beta> (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 `<main>'

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

(erb):1:in `method_missing': undefined local variable or method `config'
for #<struct C a=:alpha, b=:beta> (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 `<main>'

#######################################################################

Regression or yet another thing I don't understand?

Thanks
--
Joe

In This Thread

Prev Next