Kristof Bastiaensen <kristof / vleeuwen.org> wrote in message news:<pan.2004.06.02.00.04.02.673681 / vleeuwen.org>...
> Hi,
> 
> On Tue, 01 Jun 2004 16:29:57 -0700, Alan Chen wrote:
> 
> > To me, creating multiple instances of initialized objects feels like
> > it belongs more with the new call, rather than Integer. 
> 
> Yes, in fact it already works with the new call ;-)
> 
> > a,b,c = Array.newx(3)
> 
> a,b,c = Array.new(3) { Array.new }
> 
> Regards,
> Kristof

Yes, but can you do it for any object?

class Dbrec
  attr_accessor :city, :state
  def initialize
    @name = ''
    @state = ''
  end
end

losangeles,sandiego = Dbrec.newx(2)

or

losangeles,sandiego = Dbrec.newx(2) { |rec| rec.state = 'CA'; rec }

If anyone was actually serious about a newx method, you might want to
eliminate the need for the last "; rec" in the block above. Now, Ara
was looking for a general "do it x times and collect the results"
method and this is a "instantiate multiple mostly, similar objects"
method. My hunch is that neither one is necessary, and would mostly
trade a minor convience for a minor obfuscation of code.