From: Wilson Bilkovich Date: 2007-09-27T12:49:42+09:00 Subject: Re: Syntax for .new ? On 9/26/07, Phrogz wrote: > On Sep 26, 8:41 pm, "Chris Carter" wrote: > > Kernel is a module, so it gets the Module instance methods, and Object > > (and thus all objects) mix in Kernel, so they have const_get. The > > Module<->Class<->Object<->Kernel quartet is pretty magic in Ruby. > > I don't believe this is correct. Object.const_get works because Object > is a class, and therefore an instance of the Class class, which > inherits from the Module class. > > See http://phrogz.net/RubyLibs/RubyMethodLookupFlow.png > > (There's no official guarantee that the diagram above is correct, but > I have not yet been able to find fault with it, and it has been > reviewed and had corrections made thanks to some people quite > familiar with Ruby.) > "ri Class" also has a nice simple ASCII diagram that can be more approachable for new people. Classes, modules, and objects are interrelated. In the diagram that follows, the vertical arrows represent inheritance, and the parentheses meta-classes. All metaclasses are instances of the class `Class'. +------------------+ | | Object---->(Object) | ^ ^ ^ ^ | | | | | | | | +-----+ +---------+ | | | | | | | +-----------+ | | | | | | | +------+ | Module--->(Module) | | | ^ ^ | OtherClass-->(OtherClass) | | | | | | Class---->(Class) | ^ | | | +----------------+