Gary Wright
2/2/2007 10:06:00 PM
On Feb 2, 2007, at 2:41 PM, Drew Olson wrote:
> As you can see, if a default of 0 is not provided, inject returns an
> instance of the Attendee class rather than the value in sum. Very
> strange...
You gave a Rails example, but it is really a generic Ruby question.
If you don't give an argument to inject, it will use the first item
in the collection as the starting accumulator:
irb> [1,2,4].inject { |sum,i| p [sum,i]; sum + i }
[1, 2]
[3, 4]
=> 7