Ruby1.9, instance_eval and private methods

  • Thread starter Victor 'Zverok' Shepelev
  • Start date
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
 
T

ts

Robert said:
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
 
R

Robert Dober

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
 
T

ts

Robert said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top