From: Robert Klemme Date: 2006-02-02T18:38:20+09:00 Subject: Re: Class vs. Object James Herdman wrote: > First of all, thanks to everyone who's replied so far. I appreciate > the help and insight. > > I think I'm getting the grip of things. > >>>> "".kind_of? Object >> => true > > This confused me a bit. "" is an instance of String, right? I know > String is an instance of Object, but that doesn't really make "" an > Object... or does it? It does. Note, that String is an instance of Object (because everything is an Object in Ruby) as well as being a subclass of Object: >> String.kind_of? Object => true >> String.ancestors.include? Object => true > Another thing that confused me is this: > > String.kind_of? String > => false The class object String is by no means an instance of itself. It's rather an instance of class Class. > At first I thought that perhaps an object can't be an instance of > itself as it, itself, is defining said object (i.e. it is a Class -- > the blueprint). However, > > Object.kind_of? Object > => true Everything is an Object in Ruby - even the class Object itself. > and > > Module.kind_of? Module > => true > > What am I missing? (i) >> Class.superclass => Module >> Class.ancestors => [Class, Module, Object, Kernel] (ii) >> Module.class => Class Since Module is the super class of Class (i) and Module itself is a class (ii) obviously Module is an instance of Class as well as Module. :-) I guess, by now I have completely confused you. :-) There's a certain self referentiality in Ruby's class and object model. But this allows for some very cool features! robert