Hacker News new | past | comments | ask | show | jobs | submit login

Ruby's terminology is confusing here, but singleton methods have very little to do with the Singleton Pattern.

The Singleton Pattern is a way to design a class that ensures at runtime that only one instance of that class ever exists. Singleton methods are (effectively) methods defined on a particular object rather than being defined for all objects of a single class.

The terminology is actually correct, because the way singleton methods work is by generating an anonymous class to which only the object at hand belongs (thus that anonymous class is an example of the singleton pattern) and defining the method there, but if what you're interested in is how to define your own singleton classes then understanding singleton methods doesn't help you, and vice versa.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: