From: aero6dof@... (Alan Chen) Date: 2004-05-28T21:59:41+09:00 Subject: Re: [RCR] Numeric#of, Object.newx? "Ara.T.Howard" wrote in message news:... > this got a generally favourable reception so: > > > RCR - Numeric#of - an accumlative version of Numeric#times > > ~ > cat of.rb > class Numeric > def of > ret = [] > times{|i| ret << yield(i)} > ret > end > end > > them = 3.of{ Array.new } > p them # => [[],[],[]] To me, creating multiple instances of initialized objects feels like it belongs more with the new call, rather than Integer. Perhaps we could add a "multiple instance" new? Here is one implementation. def Object.newx( nx, *args) instances = [] if( block_given? ) nx.times { instances.push yield(self.new(*args)) } else nx.times { instances.push self.new(*args) } end instances end a,b,c = Array.newx(3)