Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: class_eval doesn't find const_missing Date: Thu, 21 Apr 2011 18:29:07 -0500 Organization: Service de news de lacave.net Lines: 22 Message-ID: <4bddc1f925e23d81a38c65fdcbc8892f@ruby-forum.com> References: <094bd73f3389eb03672e8bb25c9b8ec6@ruby-forum.com> <8d93e623bc0cb97e66f32057619d3be9@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1303428560 7744 65.111.164.187 (21 Apr 2011 23:29:20 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Thu, 21 Apr 2011 23:29:20 +0000 (UTC) In-Reply-To: <8d93e623bc0cb97e66f32057619d3be9@ruby-forum.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 382033 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <4bddc1f925e23d81a38c65fdcbc8892f@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:3346 7stud -- wrote in post #994396: > > In "The Well-Grounded Rubyist" David Black explains that constants are > like files in a file system, and depending on what "directory" you are > currently in, it will determine the "path name" to the constant that you > are interested in retrieving. It seems that class_eval does not affect > the path name to a constant. But then I don't understand how > class_eval'ing a string changes that. > Here is a blog post from 2007 asking the exact same question: http://www.pgrs.net/2007/9/12/ruby-constants-have-weird-behavior-in-class_eval As one person replied, constants are looked up by the parser, so their lexical scope determines the proper 'path' to the constant; while eval'ing a string happens in the 'dynamic scope' at runtime. -- Posted via http://www.ruby-forum.com/.