V
Victor 'Zverok' Shepelev
Can somebody please explain this:
class A
end
blk = proc do
def test
puts 'test'
end
end
a1 = A.new
a1.instance_eval &blk
a1.test #=> prints "test"
def indirect(a, &blk)
a.instance_eval &blk
end
a2 = A.new
indirect(a2, &blk)
a2.test #=> private method `test' called for #<A:0xad519c> (NoMethodError)
In words: when block for instance_eval is passed through several levels of
methods, it evaluates into private methods.
Ruby1.9 version 2008-03-29
in Ruby1.8 both a1.test and a2.test work as expected
class A
end
blk = proc do
def test
puts 'test'
end
end
a1 = A.new
a1.instance_eval &blk
a1.test #=> prints "test"
def indirect(a, &blk)
a.instance_eval &blk
end
a2 = A.new
indirect(a2, &blk)
a2.test #=> private method `test' called for #<A:0xad519c> (NoMethodError)
In words: when block for instance_eval is passed through several levels of
methods, it evaluates into private methods.
Ruby1.9 version 2008-03-29
in Ruby1.8 both a1.test and a2.test work as expected