Classes Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How does Ruby see a class?

A

For Ruby, a class is an object, that is, an instance of the class Class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why does a class can have instance variables (directly, not through instances methods)?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the scope of instance variables created directly in a class?

A

They are accessible ONLY in class methods and they can be defined in the body of the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are singleton methods?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What type of singleton structures are there?

A
  • Singleton classes: class &laquo_space;ob; end

- Singleton methods: def ob.my_method; end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly