Generally speaking, it is not. What is the difference between a class and an object?. Object in the case is the instance.
Just to make something clear before:
p1
is a variable. It has a value, so it’s an object that has there, it’s the instance of something. It doesn’t have to be a class. And in fact in almost every language that defines a class it models an object that will be stored by reference, so what it has in p1
is an instance of a pointer to an instance of another object, in the case modeled by the class Pessoa
. This is the correct definition and should be understood when one wants to learn right. Informally we say that the object is in p1
, but he’s not.
Understood this I think the question is about Ruby, the demonstrated in the code does not exist in other languages. Including much of what it shows, which would explain what is set, is something not only of Ruby, but of this implementation of the language.
Ruby uses a concept of metaclasses, so a class can be an instance of a metaclass (note the difference that it is not a normal class). Instance of a class is an object, instance of a metaclass can be a class. Although the name is "instance" in both cases are different things. Although it can be said that a class in Ruby does not cease to be an object by the philosophy of the language of objects being first-class citizens.
Again, this is something from Ruby and one language or another. Not applicable to most object-oriented languages (not to mention those that even use classes).
So to leave the generic answer, languages that do not treat classes as objects and have no metaclasses, classes are not instances of anything.
In Ruby the correct use of terminology is to say that Pessoa
is an instance of Class
, is in the documentation. I don’t know how they use it informally.
My opinion is that Ruby is closer to Javascript, IE, has classes, but at the bottom are prototypes, so you have objects that are used as groundwork for other things, including other classes, which are still objects. They are not exactly models because it occurs in real class.
It is important to separate the correct from what we use informally in day-to-day life. You can understand the informal, but it can explain wrong to the unsuspecting.
He is talking about the class being an instance and not an object, which is always.
– Maniero