Introduction
Ruby's Object Model was influenced by Smalltalk. The Smalltalk object model follows a set of simple rules that are uniformly applied. The rules are:
Rule 1
Everything is an object.
Rule 2
Every object is an instance of a class.
Rule 3
Every class has a superclass.
Rule 4
Everything happens by sending messages.
Rule 5
Method look-up follows the inheritance chain.
Ruby Object Model
In Ruby, Rule 1 is not applicable. We have seen that everything is not an object. We can say:
- Everything in the inheritance hierarchy is an Object.
- Receiver and Sender in a message sending interaction are objects.
- Every class is an object. In other words, every class is an instance of a Ruby built-in class called Class.
We have already discussed the Rule 3 and 4 in the previous section. In this section, you will learn about Rule 2 and 5.