From: "David A. Black" Date: 2008-10-01T20:51:58+09:00 Subject: Re: Mode method for Array Hi -- On Wed, 1 Oct 2008, Robert Klemme wrote: > 2008/10/1 Erik Veenstra : >> Speed is also the reason for "pre-defining" variables used in >> iterations. (6% faster!!) > > Premature optimization IMHO. As much as I like inject, I have to say I've always felt that the ones that look like this: inject({}) {|h,item| do_something; h } are kind of unidiomatic. Evan Phoenix was saying recently on IRC (I hope I'm remembering/quoting correctly) that his rule of thumb was that inject was for cases where the accumulator was not the same object every time, and that where a single object is having elements added to it, an each iteration from the source collection was better. I tend to agree, though I'm not able to come up with a very technical rationale. What say you, oh inject king? David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!