From: Daniel Lucraft Date: 2007-08-20T18:57:00+09:00 Subject: Re: Named Constructor Idiom in Ruby? Arlen Christian Mart Cuss wrote: > lost hold of the thought of how -- is there a straight-forward/neat way > to do the named constructor idiom in Ruby? You have some good answers, but here is yet another way that is quite interesting: class A class << self; private :new; end def self.something a = self.allocate # set up a somehow a end def self.otherthing a = self.allocate # set up a somehow a end end allocate is like new but without calling initialize. I believe that new is basically defined as: (1) allocate, (2) initialize. The only benefit of this over the other solutions is that it avoids calling new altogether. I have found this useful in a case where the new was very generalized and therefore slow. best, Dan -- Posted via http://www.ruby-forum.com/.