From: Dave Thomas Date: 2001-09-04T02:13:30+09:00 Subject: [ruby-talk:20791] Re: singleton help Albert Wagner writes: > I need some help with a singleton class. > > 1. With 'new' made private and replaced with 'instance', how do I properly > pass in the arguments that would normally go to the 'initialize(...)' method > via 'new'? Just use setter methods? There is a logical problem with having 'instance' take parameters (which is why is doesn't, I guess :). You could have o1 = Fred.instance("barney") o2 = Fred.instance("wilma") What would that mean? > 2. If I subclass a singleton class, then create an instance of that > subclass, do I get the same instance with the additional behaviour of the > subclass? The subclass is it's own singleton: it doesn't share the singleton parent. class A include Singleton end class B < A end a1 = A.instance a2 = A.instance b1 = B.instance b2 = B.instance a1 and a2 will be the same, as will b1 and b2. a1 will not be the same as b1. Regards Dave