On 4/19/05, Ilias Lazaridis <ilias / lazaridis.com> wrote:
> [EVALUATION] - E03c - The Ruby Object Model (Revised Documentation)
> http://groups-beta.google.com/group/comp.lang.ruby/msg/b72b4a3bfd81a48e?hl=en
> 
> -
> 
> the above thread went a little out of control.
> 
> The mostly discussed point (inherits from nil) has evolved and
> 
> please focus on the essence:
> 
> which is the term "metaclass"
> 
> -
> 
> cmd:> ri Class
> 
> "Classes, modules, and objects are interrelated. In the diagram that
> follows, the arrows represent inheritance, and the parentheses
> meta-classes. All metaclasses are instances of the class `Class'."
> 
>                            +------------------+
>                            |                  |
>              Object---->(Object)              |
>               ^  ^        ^  ^                |
>               |  |        |  |                |
>               |  |  +-----+  +---------+      |
>               |  |  |                  |      |
>               |  +-----------+         |      |
>               |     |        |         |      |
>        +------+     |     Module--->(Module)  |
>        |            |        ^         ^      |
>   OtherClass-->(OtherClass)  |         |      |
>                              |         |      |
>                            Class---->(Class)  |
>                              ^                |
>                              |                |
>                              +----------------+
> 
> -
> 
> The above documentation is false.

Not so. It is perhaps a bit unclear, but not incorrect. Also, the
concepts themselves a bit difficult to fully comprehend, but that's
how these things work, when you get into metametaclasses and so forth.

I should also add my voice to the throng complaining about the
'Object.superclass == nil' issue. Object's superclass is not nil. It
is not *represented* by nil, and nil has absolutely nothing to do with
Object's superclass.

Object *has no superclass*. All other classes have them, though, and
there's a method (superclass) that returns the superclass. since
Object is an instance of Class, it inherits this method. So there are
three possible things that could be done:
 - Make Object.superclass raise an error, perhaps NoMethodError
 - Make Object.superclass return Object
 - Make Object.superclass return nil

It would seem they chose the third option. I would assume that raising
an error was out of the question, and making the method return Object
would be inaccurate. So nil was chosen.

> The mentioned metaclasses like "(Class)" are not existent and not
> accessible whilst using standard Class/Object mechanisms.

Yes, they are accessible. Metaclasses are implemented in Ruby
(essentially) as singleton classes. All meta-class objects are
instances of the Class metaclass, and are accessible:
the expression:
  23.class
has the value of:
  Fixnum

Fixnum is the way you would refer to the metaclass. It holds all the
methods that Fixnum instances have, as well as class variables and
constants.

Note that I'm not referring to internal representation and structures,
which are irrelevant to this discussion.

> The term "metaclasses" could be exchanged with e.g. "internal
> representations of class definitions" or anything adequate.
> 
> This is _not_ the same with a metaclass (which must be a _class_).

I'm not sure what you are saying here. A metaclass is a template for
creating objects. Terminology is irrelevant. Function is.

Why do you say that ruby's metaclass objects are not true metaclasses?

> -
> 
> See the UML diagramm "TheRubyObjectModel" (V1.3) for a corrected
> clarifying version:
> 
> http://lazaridis.com/case/lang/ruby/
> 
> -
> -
> -
> 
> If I am wrong, please show me how to access the metaclass:
> 
> ClassMetaClass = Class.???
> 
> ClassMetaClass.<class operations / access>

Class's metaclass is Class. It's the stopping point - there has to be
one. If there wasn't one:

Class.class  => MetaClass
MetaClass.class => MetaMetaClass
[infinite progression detected]


It's easiest to understand Ruby's object model this way: Everything is
an object *first*, and a class member second. Metaclasses are all
objects of class Class. Metaclasses have singleton methods added to
them, and internal method tables that define the template for objects
created from them.

You can even, for the most part, create your own implementation of
Class in Ruby. just create an object, and add singleton methods. It
will work just the same as ruby's own class, minus a little syntactic
sugar.

Someone mentioned that you need to learn more about Ruby's singleton
methods. They were correct. Understanding Ruby's singleton method
concept is *essential* to full understanding of the object model,
imho.

-

Object, the most generic metaclass for objects, is an object. If you
check the ancestors of Object's class, you will find Object listed.
This is because Class is a subclass of Object itself. Object is where
are things, classes and objects are derived from. In Ruby, Object is
God.

There is a nice discussion of this here[1], especially in the third
chapter. It gets into metaclasses, specifically how they are used in
Ruby.

[1] http://www.visibleworkings.com/little-ruby/

PS
please don't attack me for feeding the troll. just add this thread to
your filter :)