Let's start by looking at an object created from a simple
class. Figure 19.1 on page 239 shows
an object referenced by a variable,
lucille
, the object's class,
Guitar
, and that class's superclass,
Object
. Notice how the
object's class reference (called
klass
for historical reasons
that really bug Andy) points to the class object, and how the
super
pointer from that class references the parent class.
When Ruby executes
Guitar.strings()
, it follows the same process
as before: it goes to the receiver, class
Guitar
, follows the
klass
reference to class
Guitar$'$
, and finds the method.
Finally, note that an ``S'' has crept into the flags in class
Guitar$'$
. The classes that Ruby creates automatically are
marked internally as
singleton classes.
Singleton classes are
treated slightly differently within Ruby. The most obvious difference
from the outside is that they are effectively invisible: they will
never appear in a list of objects returned from methods such as
Module#ancestors
or
ObjectSpace::each_object
.