From: 7stud -- Date: 2011-04-22T07:38:53+09:00 Subject: Re: class_eval doesn't find const_missing 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/.