Ruby1.9, instance_eval and private methods

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

Victor ‘Zverok’ Shepelev wrote:

Can somebody please explain this:

no, probably not :slight_smile:

Ruby1.9 version 2008-03-29

probably a bug.

Guy Decoux

On Thu, Apr 24, 2008 at 3:27 PM, ts [email protected] wrote:

Ruby1.9 version 2008-03-29

probably a bug.
Guy do you think that Victor should file a bug report, I strongly
believe that this would be helpful.

Robert

Robert D. wrote:

Guy do you think that Victor should file a bug report, I strongly
believe that this would be helpful.

no, this is a known problem because it’s already corrected in my
private version

Guy Decoux

On Fri, Apr 25, 2008 at 10:03 AM, ts [email protected] wrote:

Robert D. wrote:

Guy do you think that Victor should file a bug report, I strongly
believe that this would be helpful.

no, this is a known problem because it’s already corrected in my
private version

ok that’s why I asked, there was no bug for this on Rubyforge’s tracker,
right?
Thx
Guy

http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Robert D. wrote:

ok that’s why I asked, there was no bug for this on Rubyforge’s tracker, right?

Well, each time that you see ‘instance_eval &block’ you can expect
a bug and this was reported in rubyforge

Guy Decoux

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs