From: Xavier Noria Date: 2006-10-22T00:20:44+09:00 Subject: Re: instance_eval && class_eval On Oct 21, 2006, at 3:40 PM, ts wrote: >>>>>> "P" == Phrogz writes: > > > P> I'm not surprised by that. I'm surprised that standard def...end > syntax > P> inside instance_eval behaves differently from being in the class > scope, > P> when the self object in both cases is the same. > > def is a keyword and it don't use self to know where the method > must be > defined but it use an "internal" variable the "current" class. Good! Is the existence of that "current" class vs self documented somewhere or do you know it from the sources? Does it have a name in jargon? What about the fact that instance_eval switches current to the singleton class of self? I saw it works for objects which are not classes as well (which is a redundant exercise to reinforce this): class A end a = A.new b = A.new a.instance_eval do def croak puts "croak!" end end a.croak b.croak gives croak! tmp/foo.rb:13: undefined method `croak' for # (NoMethodError) so the "current" class is the singleton class of the object a as well. -- fxn