Module 24 Β· The Ruby Object Model β Lesson 5 of 6 Β· ~9 min
Singleton Classes & Class Methods
Where do class methods actually live?
You've written def self.roster a hundred times. Here's the question that reveals whether you understand it: a method belongs to a class, and instances look it up in their class β so where does a class method live, given that a class is itself an object? The answer is the singleton class (a.k.a. metaclass or eigenclass): a hidden, per-object class that holds methods belonging to that one object alone.
In an interview, say: "A class method is a singleton method on the class object.
def self.foodefinesfooin the class's singleton class, which is why instances can't see it but the class can. Class methods aren't a separate feature β they're the object model applied to the class-as-an-object."