From: Day Date: 2008-02-06T04:23:16+09:00 Subject: Re: eval vs. class_eval ------=_Part_13990_10410019.1202239401223 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Carl and I are working on the same project, here. What he means is this: Fil.add_class :NewClass1 Fil::NewClass1.add_class :NewClass2. We expected eval to create scope nesting that mirrors the inheritance, but apparently even children of NewClass1 are scoped inside Fil (as opposed to inside their parents). This actually appears to be the behavior of class_eval. It's confusing as to why eval would do that, though. Is that more clear? Ben On Feb 5, 2008 12:03 PM, Jan wrote: > > > > The structure I observe with running the eval version is > > > > class Fil > > class NewClass1 > > end > > class NewClass2 > > end > > end > > > I tried both version all get the first result, I think this is a > reasonable > result(Ruby 1.8.6 on win32). Why do you think the result should be in the > 2nd form? > > > > > > > > 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/. > > > > > > > -- > Fly on wheels. > ------=_Part_13990_10410019.1202239401223--