13.1. Where the singleton methods are: The singleton class

Most of what happens in Ruby involves classes and modules, containing definitions of instance methods

class C
  def talk
    puts "Hi!"
  end
end

and, subsequently, the instantiation of classes and the calling of those instance methods:

But as you saw earlier (even earlier than you saw instance methods inside classes), you can also define singleton methods directly on individual objects:

And you’ve also seen that the most common type of singleton method is the class method—a method added to a ...

Get The Well-Grounded Rubyist, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.