From: Joshua Ballanco Date: 2012-03-18T10:20:22+09:00 Subject: [ruby-core:43379] [ruby-trunk - Bug #5544] Lookup scope for class variables in class_eval'd procs changed in 1.9.3 Issue #5544 has been updated by Joshua Ballanco. I suppose so long as it is documented, the difference is ok. I think this can be closed in that case. ---------------------------------------- Bug #5544: Lookup scope for class variables in class_eval'd procs changed in 1.9.3 https://bugs.ruby-lang.org/issues/5544#change-24684 Author: Joshua Ballanco Status: Closed 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/