From: Robert Klemme Date: 2007-08-31T06:10:09+09:00 Subject: Re: How to make an array of hashes to a single array with all the values of these hashes ? On 30.08.2007 16:47, Todd Benson wrote: > On 8/30/07, Robert Klemme wrote: >> 2007/8/29, yermej@gmail.com : >>> On Aug 29, 2:53 pm, dima wrote: > >>> my_new_array = myvalue.inject([]) {|arr, h| arr + h.values} >> That's already pretty good (you used #inject ;-)) but this one is >> slightly more efficient: >> >> my_new_array = myvalue.inject([]) {|arr, h| arr.concat h.values} > > Nice. You beat me to it. One of these days, though, I'll read all > the Ruby source and exact vengeance upon you guys :) *gulp* > For a short repeat of the record for the nubies, #concat supposedly > doesn't create new objects, and thus is more "efficient". To be fair I'd have to say that often intuition errs about what is fast and what is wrong in Ruby. Sometimes algorithms that are supposedly faster (for example because a collection is iterated only once vs. several times) are actually slower than other variants - at least for the size of collections that programs typically deal with. (In this case if's of course better to save all those superfluous intermediate arrays. :-)) Kind regards robert