From: Raul Parolari Date: 2007-11-17T15:41:10+09:00 Subject: Re: "instance_eval" (eg, sent to a class object) Rick Denatale wrote: > Now all this begged a question in my mind. That is, what's the > difference between instance_eval and class_eval (with its alias > module_eval). A little digging in the 1.8.6 MRI code reveals that > both use the same underlying code, but the inner c function > specific_eval (in eval.c) takes both a klass and a self argument. > > Both rb_object_instance_eval (the code behind Kernel#instance_eval) > and rb_mod_module_eval (the code behind both Module#module_eval and > Module#class_eval) set the self argument to the receiver. > > rb_obj_instance_eval sets the klass argument to the singleton_class of > the receiver (creating it if it doesn't already exist), unless the > receiver is an immediate object (a Fixnum, or nil, true, or false) in > which case it sets klass to nil. > ... Very nice analysis work; with the Figure 24.2 (made famous by Gregg) of the Pickaxe at hand, and Rick's detailed description of the klass pointer adventures, we can now connect the dots (at least, most of them). Bravo! Raul -- Posted via http://www.ruby-forum.com/.