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


Groups > comp.lang.ruby > #3343

Re: class_eval doesn't find const_missing

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news.musoftware.de!wum.musoftware.de!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail
From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: class_eval doesn't find const_missing
Date Thu, 21 Apr 2011 18:14:47 -0500
Organization Service de news de lacave.net
Lines 35
Message-ID <935fb249044a148a6bc43c8550b45654@ruby-forum.com> (permalink)
References <094bd73f3389eb03672e8bb25c9b8ec6@ruby-forum.com> <92428472-A26F-4472-ACA4-B969CC5C1333@agrussell.com>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1303427713 6028 65.111.164.187 (21 Apr 2011 23:15:13 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Thu, 21 Apr 2011 23:15:13 +0000 (UTC)
In-Reply-To <92428472-A26F-4472-ACA4-B969CC5C1333@agrussell.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 382031
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <935fb249044a148a6bc43c8550b45654@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:3343

Show key headers only | View raw


Stephen Prater wrote in post #994391:
> 
http://stackoverflow.com/questions/3015947/ruby-how-does-constant-lookup-work-in-instance-eval-class-eval
>
> Const lookup varies between 1.8, 1.9.1, and 1.9.2.
>
> Basically, constants are lexically scoped.
>
> You can use "const_get" I believe to lookup your constant in the
> current binding rather than in the lexical scope.
>

That works for me in ruby 1.9.2:

DummyClass.class_eval do
  puts const_get(:NAME)
end

--output:--
dummy constant

That makes sense because the call is really:

  puts self.const_get(:NAME)

and because self is equal to DummyClass, that is equivalent to:

  puts DummyClass.const_get(:NAME)

which like class_eval'ing a string does the lookup in the "directory" 
DummyClass.

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