From: Jacob Fugal Date: 2006-11-16T00:49:13+09:00 Subject: Re: Design problem with 'inject' On 11/14/06, Gary Boone wrote: > arr.inject(0) do |sum, i| > next if (i==3) > sum += i > done Others have already posted clarifying the semantics of inject and proposing alternate solutions, so I won't bother with that. I just wanted to point out another alternate: arr.select{ |i| i != 3 }.inject(0){ |sum, i| sum + i } I like to use block-taking functions on Enumerables like unix pipes and let the body of each block do the simplest thing possible. The only potential drawback to breaking the filter apart like this is that the current implementation of ruby turns this into two loops. If your array is large, this can be a problem. But for most cases where you're not doing number crunching, the inefficiency is negligible. Just another possibility... Jacob Fugal