26 Dec '13, 12pm

Singleton - APIdock

Making Klass.new and Klass.allocate private. Overriding Klass.inherited(sub_klass) and Klass.clone() to ensure that the Singleton properties are kept when inherited and cloned. Providing the Klass.instance() method that returns the same object each time it is called. Overriding Klass._load (str) to call Klass.instance(). Overriding Klass#clone and Klass#dup to raise TypeErrors to prevent cloning or duping.

Full article: http://apidock.com/ruby/Singleton

Tweets