On Apr 4, 2005, at 9:04 AM, Ilias Lazaridis wrote: > George Moschovitis wrote: >>> There are nice diagrams of this relationship in Programming Ruby >>> (Chapter 24: Objects and Classes). > > Is this book available online? The first edition of the book (now in its second edition) is available online, but the figures aren't in it. They are what you are after. >> or you can just use ri: >> ri Class >> generates an ASCII version of the diagrams. > > where do i use it? ri should be installed with Ruby. The documentation may or may not have been, depending on how you installed Ruby. If it is installed, typing "ri Class" at the command-line will fetch the document. I'll inline the document George mentioned below, for reference, but I don't personally feel it's as helpful as the figures in Programming Ruby. James Edward Gray II -------------------------------------------------- Class: Class < Module Classes in Ruby are first-class objects---each is an instance of class Class. When a new class is created (typically using class Name ... end), an object of type Class is created and assigned to a global constant (Name in this case). When Name.new is called to create a new object, the new method in Class is run by default. This can be demonstrated by overriding new in Class: class Class alias oldNew new def new(*args) print "Creating a new ", self.name, "\n" oldNew(*args) end end class Name end n = Name.new produces: Creating a new Name 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) | ^ | | | +----------------+ ------------------------------------------------------------------------ Class methods: new Instance methods: allocate, inherited, initialize_copy, new, superclass