From: Carl Youngblood Date: 2008-02-05T23:23:19+09:00 Subject: Re: eval vs. class_eval Day wrote: > On Feb 4, 2008 4:16 PM, Thomas Wieczorek > wrote: > >> eval and class_eval work on different scopes. eval works just in its >> current scope(here your method), however class_eval works for the >> whole class(your Fil) > > > Are you saying there's some kind of weird scope shift up? If you run > version > two (with eval) and create a child class and a grandchild class, it > looks > like it creates the grandchild within Fil, not within Fil's child. The > class_eval version creates it so that Fil's child is within Fil and > Fil's > grandchild is within Fil's child. At least... that's what's baffling to > ME > about this. Maybe Carl can provide an example. > > If I'm guessing totally wrong, what's going on, exactly, with the scope > here? > > > Ben Right. The structure I observe with running the eval version is class Fil class NewClass1 end class NewClass2 end end but running class_eval I observe class Fil class NewClass1 class NewClass2 end end end I believe the second form should be the result for either eval or class_eval since they both default to a receiver of self, and when adding NewClass2 the receiver self should be Fil::NewClass1, not Fil. I'm guessing either what I'm observing is wrong somehow or there is a special rule about eval and the context it evaluates in? Carl -- Posted via http://www.ruby-forum.com/.