From: Kent Dahl Date: 2002-07-23T20:06:14+09:00 Subject: Re: define_method with super in the proc Tom Sawyer wrote: > the problem is that #makeproc is interpreting the super for itself and > thus reports an error of 'makeproc' super: no superclass method > 'makeproc' (NameError). obviously that's not what i want. how strange. > it dosen't try to define @y = 10 for makeproc's object. Even worse, it seems to define @y = 10 for the class object B. In fact, you're not getting tied to the makeproc's object, you're getting tied to the class object B itself. I expanded on your example: class A attr_reader :x, :y def doit @x = 5 puts "A.doit" end end def makeproc Proc.new { @y = 10 puts "B.doit " + self.inspect } end B = Class.new(A) B.class_eval { alias doit_super_A doit define_method(:doit, makeproc ) } b = B.new b.doit #=> B.doit B puts b.y #=> nil puts B.instance_eval{@y} #=> 10 By the output of "b.doit", you see that the proc is executed in the context of the class object B, and not the instance. Is this a bug? It violates my PoLS atleast. I'm running ruby 1.6.6 (2001-12-26) [i586-linux-gnu] and ruby 1.6.7 (2002-03-01) [i686-linux] > how do i work > around this? I was going to suggest passing :doit_super_A into the makeproc and using self.send, but in light of the above that won't help much. *back to scratching head* -- (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 4. year ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)