From: lasitha Date: 2008-08-30T03:12:29+09:00 Subject: Re: Class === On Fri, Aug 29, 2008 at 10:16 PM, RubyTalk@gmail.com wrote: > On Thu, Aug 28, 2008 at 5:53 PM, David A. Black wrote: >> On Fri, 29 Aug 2008, RubyTalk@gmail.com wrote: >> >>> I need help with === and Objects >>> 270 Array === Array >>>> ] false [< >>> 290 Array == Array >>>> ] true [< >>> 300 Object === Object >>>> ] true [< >>> 310 Object.class >>>> ] Class [< >>> 320 Object === Class >>>> ] true [< >>> > I guess the thing i still struggle with is these lines: > >> The reason is that all objects are instances of Object and its >> descendants, including the class object Object. So Object has a unique >> relationship, among classes, to itself. > > Mostly the " the class object Object" Not sure if i can explain this well but i'll take a shot at it. Starting with the obvious, all objects have a class: 01> class X; end --> nil 02> X.new.class --> X More interestingly, this applies to classes themselves too: 03> X.class --> Class In other words X is an instance of class. Now, plain old objects are no different: 04> Object.new.class --> Object 05> Object.class --> Class But Class itself is also an object (as David said, everything is an Object): 06> Class.ancestors --> [Class, Module, Object, PP::ObjectMixin, Kernel] So, coming back to your original example: 07> Object === Object --> true This is true because the class of Object is Class and Class is a descendent of Object. The key here (methinks) is that you are asking whether the _class of Object_ is a descendent of Object. Compare that to: 08> Object.new === Object --> false False because the class of an Object _instance_ is Object and that isn't a descendent of Object. Hope that didn't confuse you further! Cheers, lasitha.