From: Robert Dober Date: 2008-03-30T23:32:58+09:00 Subject: Re: inject's pathological case... On Sun, Mar 30, 2008 at 3:34 PM, Rick DeNatale wrote: > On 3/30/08, 7stud -- wrote: > > > By the way, using inject() is inefficient--not to mention confusing. > > You might as well pretend it doesn't exist. > > Or much better, understand that it's a way to reduce/fold the elements > of an enumerable into a single value. > http://en.wikipedia.org/wiki/Fold_%28higher-order_function%29 > > Enumerable#inject is very useful, as long as you don't treat it as > Maslow's hammer and use it in inappropriate ways, such as giving it a > block like in the original posting to this thread. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > > Completely agree with Rick and furthermore you will not be able to understand Ruby code written by others if you do not have a basic understanding of inject. I found this code in Ruby1.9 though if result.size > 0 and result.inject(false) {|k,s| s or k} that kind of code explains why inject has a bad reputation. Cheers Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein