Actions
Bug #5544
closedLookup scope for class variables in class_eval'd procs changed in 1.9.3
Description
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
Actions
Like0
Like0Like0Like0Like0Like0