From: "David A. Black" Date: 2005-02-13T06:22:20+09:00 Subject: Re: const_defined? and inheritance Hi -- On Sun, 13 Feb 2005, Kevin Howe wrote: > It seems that const_defined? doesnt search it's superclass: > > class A > FOO = 'BAR' > end > > class B < A; end > > puts A.const_get(:FOO) # => 'BAR' > puts A.const_defined?(:FOO) # => true > puts B.const_get(:FOO) # => 'BAR' > puts B.const_defined?(:FOO) # => false > > I had expected B.const_defined?(:FOO) to be true. Seems strange that > const_get does the lookup while const_defined? doesn't. Is there a reason > for this behaviour? > > The following takes care of it: > > class A > def self.const_defined?(symbol) super || > superclass.const_defined?(symbol) end > end > > But would like to know why this is. I think they're just two different operations. The constants a module can see ("get") is a superset of the constants it's defined. David -- David A. Black dblack@wobblini.net