On Aug 27, 8:03 am, Colin Law <[email protected]> wrote:
> 2009/8/26 Ruby on Rails: Talk <[email protected]>:
>
> > I really have no idea why this is not working or not returning a zero
> > value?! Any ideas please?
>
> A bit of a guess here but it may be that fact that this will attempt
> to include some nil values in the sum as the result of the block will
> be nil (I think) for values that do not match.  Perhaps this is ok if
> the first record is included in the sum but later ones not (so it is
> performing value + nil) but fails if the first one is not included in
> the sum (so it performs nil + value).  Just a guess.
>

That is indeed it - the value of an if statement where the condition
is not met. One way of solving this would be to change the code to

if ...
  item.spend
else
 0
end

Fred
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to