Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3346

Re: class_eval doesn't find const_missing

From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: class_eval doesn't find const_missing
Date 2011-04-21 18:29 -0500
Organization Service de news de lacave.net
Message-ID <4bddc1f925e23d81a38c65fdcbc8892f@ruby-forum.com> (permalink)
References <094bd73f3389eb03672e8bb25c9b8ec6@ruby-forum.com> <8d93e623bc0cb97e66f32057619d3be9@ruby-forum.com>

Show all headers | View raw


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/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

class_eval doesn't find const_missing Andrew Berkeley <andrew.berkeley.is@googlemail.com> - 2011-04-21 14:20 -0500
  Re: class_eval doesn't find const_missing Stephen Prater <stephenp@agrussell.com> - 2011-04-21 16:34 -0500
    Re: class_eval doesn't find const_missing 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-21 18:14 -0500
  Re: class_eval doesn't find const_missing 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-21 17:38 -0500
    Re: class_eval doesn't find const_missing 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-21 18:29 -0500
  Re: class_eval doesn't find const_missing Brian Candler <b.candler@pobox.com> - 2011-04-21 16:26 -0500
  Re: class_eval doesn't find const_missing Andrew Berkeley <andrew.berkeley.is@googlemail.com> - 2011-04-22 14:43 -0500

csiph-web