Hi --

On Fri, 17 May 2002, Hal E. Fulton wrote:

> ----- Original Message -----
> From: "Dave Thomas" <Dave / PragmaticProgrammer.com>
> To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
> Sent: Thursday, May 16, 2002 4:47 PM
> Subject: Re: Metaclasses...
>
>
> > "Hal E. Fulton" <hal9000 / hypermetrics.com> writes:
> >
> > > 2. Why do we create a metaclass if all classes are
> > > instances of Class? Couldn't Class have been used
> > > as a generic metaclass?
> >
> > At the risk of doing a Ron Jeffries, I'll answer with a question.
> > Where would MyClass's class methods live?
>
> Waxahachie?
>
> No, seriously... why couldn't they live in Class?

For one thing, if you had:

  class A
    def A.thing
    end
  end

  class B
    def B.thing
    end
  end

and if class << A and class << B were both Class, Class would have a
name conflict at #thing.

> I'm probably being dense. The simple difference between
> "X is an instance of Y" and "X inherits from Y" confuses
> me.
>
> I have spent many hours staring glassy-eyed and
> muttering, "Class is an object... Object is a class...
> Object is an object... Class is a class..."

There's definitely a circularity at the top of the family tree, where
this stuff is bootstrapped.  One way to think about it is that, even
before you, as programmer, can use class Class to create a new Class
object, Ruby can create new Class objects internally.  So when you
wonder, how can the type of Object be Class, if Class is an Object,
you can think of it as: Ruby already knew how to create a class (such
as Object), prior to making the class Class available to you so that
you could create your own Class objects.

To quote [myself in :-] "Teach Yourself Ruby in 21 Days": "...even
though class Class is what enables you the programmer to create new
classes, it's really just a gateway to something that Ruby can already
do internally."

(Probably more of a conceptual aid than a technically rigorous
account... but hopefully useful.)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav