The Singleton Pattern
Welcome to the second in a series of posts about anti-patterns in Ruby ! What is a singleton? A singleton is a single instance of a class, particularly a single instance of a class - to be a singleton, a class must have the property of only being able to be created once (note that a singleton could not be created yet, so a singleton doesn't have the property of necessarily existing). Why use a Singleton pattern? * You have a single resource that you need to model - for instance, a log file. * You need quick access to a particular resource throughout your system and don't want to have to remake it every time. * Having more than one of a resource might be dangerous in your system - for example, if you're designing hardware related to a physical system, it may cause serious problems if you have multiple instances of an object floating around and different parts of the software are making calculations from different representations of a real-world machine part. * ...other rea...