From: Todd Benson Date: 2007-08-31T09:09:50+09:00 Subject: Re: How to make an array of hashes to a single array with all the values of these hashes ? On 8/30/07, Robert Klemme wrote: > 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* Hopefully, everybody took that in good stride :) > 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. :-)) Yes. I've noticed a good deal of discussion along these lines in this group, and it fascinates me (thus the comment about the source code :). Also, there are good lessons about software engineering in general on this list (a group comprised of very smart people that sometimes I feel as if I do not really belong), like: being careful about emphasizing efficiency in the design phase, and then grabbing the program by the proverbial balls later on :) > Kind regards > > robert Learning a ton of things every day, Thanks, Todd