From: Robert Klemme Date: 2007-08-31T15:00:19+09:00 Subject: Re: How to make an array of hashes to a single array with all the values of these hashes ? On 31.08.2007 02:09, Todd Benson wrote: > 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 :) I can speak for myself only but I did. >> 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 :) :-) If that feeling haunts you again simply remember that all smart people started out as dumb as everyone else. Also, as long as one actually feels stupid one won't forget that one does not know the answer to everything - it helps me keeping things in perspective. Much of this smartness is just a matter of experience, namely having run into the same traps and made the same mistakes that others haven't hit so far. :-) And: You are absolutely right: this is a great community and it's good that someone states it from time to time. > Learning a ton of things every day, Definitively! Kind regards robert