[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Design problem with 'inject'
From:       Gary Boone <dr () garyboone ! com>
Date:       2006-11-15 8:51:26
Message-ID: adfb9ccef633ae0e96eaecfc5b1a5731 () ruby-forum ! com
[Download RAW message or body]


Those are several good suggestions.

   next sum if (i == 3)

strikes me as simple and clear. Provided you know that the block result 
is what matters, you can stay out of trouble.

Simplifying the example, the trouble with inject is that

   arr.inject(0) { |sum, i| sum += i }
   arr.inject(0) { |sum, i| sum + i }

both produce the same result. Yuk.

Maybe it should be posted somewhere as a potential 'gotcha'.

-- 
Posted via http://www.ruby-forum.com/.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic