6.3: Every Object Is an Instance of a Class
- Page ID
- 39600
Every object has a class; you can find out which one by sending it the message class.
1 class >>> SmallInteger
20 factorial class >>> LargePositiveInteger
'hello' class >>> ByteString
(4@5) class >>> Point
Object new class >>> Object
A class defines the structure of its instances via instance variables, and the behavior of its instances via methods. Each method has a name, called its selector, which is unique within the class.
Since classes are objects, and every object is an instance of a class, it follows that classes must also be instances of classes. A class whose instances are classes is called a metaclass. Whenever you create a class, the system automatically creates a metaclass for you. The metaclass defines the structure and behavior of the class that is its instance. 99% of the time you will not need to think about metaclasses, and may happily ignore them. (We will have a closer look at metaclasses in Chapter : Classes and Metaclasses.)