Everything is an object
We will begin our journey with objects.
In Ruby, just like in real life, our world is filled with objects. Everything is an object - integers, characters, text, arrays - everything.
To make things happen using Ruby, one always puts oneself in the place of an object and then has conversations with other objects, telling them to do stuff.
Roleplaying as an object in your program is an integral part of object-oriented programming.
To know which object you are at the moment, one may use the keyword self
.
Try it for yourself:
As you can see, if you don't specify which object you are, you automatically play the role
of the main
object that Ruby provides us by default.
We'll delve into how one can play the role of different objects and why this is useful a little further down the line.