From: "David A. Black" Date: 2004-08-20T07:11:38+09:00 Subject: Re: Obtaining object in const_missing Hi -- On Fri, 20 Aug 2004, T. Sawyer wrote: > I'm stumped. Is there any way to do this? > > class Object > def self.const_missing(name) > p self # => X > # Okay, but how do I get at object x? > x = ? > if x.respond_to?(:myconstant) > return "Gotchya" > else > raise # proper error? > end > end > end > > class X > def myconstant > puts NewConstant > end > end > > x = X.new > x.myconstant Sort of thinking it through aloud, so to speak: I think the problem might be that x has no special status inside const_missing. Consider that you could also do: class Y def otherconstant puts X::NewConstant end end y = Y.new y.otherconstant and then y would be playing the role that x is playing in your example. So it becomes a pretty general role: the object that received a message that resulted in a method call during the course of which some class or module's missing constant was referenced. I'm not sure that much history and context is really the business of the class or module whose constant it is. David -- David A. Black dblack@wobblini.net