From: Ryan Davis Date: 2011-03-10T08:06:30+09:00 Subject: Re: double singleton? On Mar 9, 2011, at 14:34 , 7stud -- wrote: > Roger Pack wrote in post #986564: >> Hello all. >> >> Noticed this behavior: >> >>>> require 'singleton' >> => true >>>> class A; include Singleton; end >> => A >>>> A.instance >> => # > > I looked through the ruby docs and neither Object, Module, Class, nor > Singelton have a method named 'instance'. Where does that come from? 9998 % ri Singleton = Singleton (from ruby core) ------------------------------------------------------------------------------ The Singleton module implements the Singleton pattern. Usage: class Klass include Singleton # ... end * this ensures that only one instance of Klass lets call it ``the instance'' can be created. a,b = Klass.instance, Klass.instance a == b # => true a.new # NoMethodError - new is private ... * ``The instance'' is created at instantiation time, in other words the first call of Klass.instance(), thus class OtherKlass include Singleton # ... ...