Classes Flashcards
How does Ruby see a class?
For Ruby, a class is an object, that is, an instance of the class Class.
Why does a class can have instance variables (directly, not through instances methods)?
This is because a class is an object and any object can have its instance variables. An instance variable of the class doesn’t collide with the instances variables of the objects created from it.
What is the scope of instance variables created directly in a class?
They are accessible ONLY in class methods and they can be defined in the body of the class.
What are singleton methods?
They are methods that belong to a single object rather than to an entire class. Class methods are the most common type of singleton methods, that is due to a class is an object and those methods belong to that single object.
What type of singleton structures are there?
- Singleton classes: class «_space;ob; end
- Singleton methods: def ob.my_method; end