Meet The Singletons

These guys confused the heck outta me until Russ Olsen shined some light on them.

Slightly different to the Singleton Pattern of software design, Ruby employs the singletons for its own wizardry. There are 2 members of the singleton family — methods and classes. A singleton method is a method which is only available to one instance of a class. The singleton class is simply where these singleton methods live[footnote]It’s actually added anonymously into the class hierarchy for that instance.[/footnote].

Useful? Well, you know class methods… Turns out, class methods don’t exist. They’re actually singleton methods, because any class is a single instance of the Class class. Mhmm…