From: Koichi Sasada Date: 2012-03-11T16:41:42+09:00 Subject: [ruby-core:43206] [ruby-trunk - Bug #5544][Assigned] Lookup scope for class variables in class_eval'd procs changed in 1.9.3 Issue #5544 has been updated by Koichi Sasada. Category set to core Status changed from Open to Assigned Assignee set to Shugo Maeda ---------------------------------------- Bug #5544: Lookup scope for class variables in class_eval'd procs changed in 1.9.3 https://bugs.ruby-lang.org/issues/5544 Author: Joshua Ballanco Status: Assigned Priority: Normal Assignee: Shugo Maeda Category: core Target version: ruby -v: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] When using class_eval with a proc, references to class variables scoped to the receiver in 1.9.2, but in 1.9.3 class variables are now lexically scoped to the environment of the proc. For example, this code: class Foo def initialize @@value = "Set from Foo initialize" end def report @@value end end class Bar def initialize @@value = "Set from Bar initialize" end def report @@value end def monkey Foo.class_eval do def set(value) @@value = value end end end end b = Bar.new b.monkey f = Foo.new puts "Before monkeying:" puts "Bar's class var: #{b.report}" puts "Foo's class var: #{f.report}" f.set("Set through Monkey") puts "After monkeying:" puts "Bar's class var: #{b.report}" puts "Foo's class var: #{f.report}" Running under 1.9.2-p290: Before monkeying: Bar's class var: Set from Bar initialize Foo's class var: Set from Foo initialize After monkeying: Bar's class var: Set from Bar initialize Foo's class var: Set through Monkey Running under 1.9.3-p0: Before monkeying: Bar's class var: Set from Bar initialize Foo's class var: Set from Foo initialize After monkeying: Bar's class var: Set through Monkey Foo's class var: Set from Foo initialize -- http://bugs.ruby-lang.org/