From: Logan Capaldo Date: 2007-08-30T07:47:09+09:00 Subject: Re: Adding elements of one array to another On 8/29/07, Todd Benson wrote: > On 8/29/07, Ari Brown wrote: > > I can't remember who asked this a while ago, but while I was > > stumbling through my Programming Ruby book, I found a nice method in > > array that will instantly do the trick: Array#concat > > > > > > a = [1, 2] > > b = [3, 4] > > a.concat(b) #=> [1, 2, 3, 4] > > There's also a+=b. I'm not sure if there's a difference. > There is. a += b --> a = a + b, and a + b will always allocate a new array. a.concat(b) will try to use any space already allocated in a, and only if there is not enough will it regrow a. > Todd > >