From: Warren Brown Date: 2004-08-20T06:21:31+09:00 Subject: Re: Obtaining object in const_missing T., > 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 As our own comment points out, self is class X, not the instance of class X currently pointed at by the variable x. What you want to do is call Module#method_defined? instead of Object#respond_to?, so your if statement becomes: if method_defined?(:myconstant) I hope this helps. - Warren Brown