I'm not sure but this can add some confusion.
I remember we removed the possibility to pass a block to sum and count to avoid confusion of users that may think the block will change the database query.
Hi all,I realize this behavior is by design, and in some respects the right thing to do. It also pre-dates the addition of Enumerable#count. I'm wondering, however, if it's possible/desirable to allow the caller to access the Enumerable versions under certain conditions. I originally wrote the up as an issue, but was informed this would be the better venue. I'm linking to the original issue on Github because the syntax highlighting is nice.TIA for taking the time to think this over.--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
I just ran into this issue, and I would actually call it a bug since it causes very unexpected behavior:
> User.count { |user| user.not_a_method! } => 10
So the block isn't even being evaluated. I'm fine if we don't delegate to Enumerable, but I would expect #count
to at least raise an error if a block is given so people don't accidentally try to count with a predicate and get the wrong answer.
submissions.to_a.count(&:incomplete?)
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.