Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3340
| X-FeedAbuse | http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 |
|---|---|
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!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 17:38:53 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 42 |
| Message-ID | <8d93e623bc0cb97e66f32057619d3be9@ruby-forum.com> (permalink) |
| References | <094bd73f3389eb03672e8bb25c9b8ec6@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 1303425560 2297 65.111.164.187 (21 Apr 2011 22:39:20 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Thu, 21 Apr 2011 22:39:20 +0000 (UTC) |
| In-Reply-To | <094bd73f3389eb03672e8bb25c9b8ec6@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 | 382028 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <8d93e623bc0cb97e66f32057619d3be9@ruby-forum.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:3340 |
Show key headers only | View raw
Andrew Berkeley wrote in post #994369:
>
> Interestingly, an explicit call to #const_missing inside a class_eval
> block DOES work.
>> DummyClass.class_eval {const_missing :ANOTHER_CONSTANT}
> => "this ANOTHER_CONSTANT was captured by #const_missing"
>
> Anybody understand this, and is there a way to get around it?
>
This line:
DummyClass.class_eval {const_missing :ANOTHER_CONSTANT}
is equivalent to:
DummyClass.class_eval {
self.const_missing(:ANOTHER_CONSTANT)
}
And because class_eval() changes self inside the block to be equal to
the receiver, the above is equivalent to:
DummyClass.class_eval {
DummyClass.const_missing(:ANOTHER_CONSTANT)
}
..producing the output you see.
Also, note the output here:
DummyClass.class_eval do
puts self::NAME
end
--output:--
dummy constant
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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