From: Arlen Cuss Date: 2008-02-29T08:48:50+09:00 Subject: Re: constants defined in Kernel are also defined in Object? On Fri, Feb 29, 2008 at 10:30 AM, Joel VanderWerf wrote: > But: > > > Kernel.const_set(:FOO, 42) > class Foo; end > p Foo::FOO # ==> 42 > > p Foo.const_defined?(:FOO) # ==> false > > p Object.const_defined?(:FOO) # ==> true Indeed! It works in both cases because Foo is an Object, Object includes Kernel -- Foo won't tell you that FOO is defined because Foo didn't define it itself! I've been writing a new parser and byte-code VM for Ruby recently (http://rubyex.sairyx.org/, excuse the advertising), which meant figuring out the whole Ruby object model. This had me tricked at several stages, but here's how I summarised it to myself: 1. Foo is an instance of Object [eventually]. 2. Object mixes in Kernel. 2.a. Kernel's constants are Object's too. 3. Foo::SOME_CONST will see through to Object::SOME_CONST and then that to Kernel::SOME_CONST. Correct me if I'm wrong in some detail. Arlen