From: William James Date: 2006-11-16T02:30:37+09:00 Subject: Re: Design problem with 'inject' Gary Boone wrote: > Ruby's inject has a design that can lead to hard to find bugs. The > problem is that you don't have to specify what is summed; the value of > the block is summed. That means 'next' can lead to a bug. Here's an > example: > > No problem: > > arr.inject(0) do |sum, i| > sum += i > done > > But suppose you need to skip some elements, so you add a 'next' > statement. > Problem: > > arr.inject(0) do |sum, i| > next if (i==3) > sum += i > done > [1,2,3,4,5].reject{|n| n==3}.inject{|s,n| s+n}