Patrick Byrne
2011-Jul-05 18:31 UTC
Seeking Feedback on Pull Request 1932 (Added Enumerable#count_by and tests)
All, I created a pull request that adds Enumerable#count_by, which leverages Enumerable#group_by to return the counts elements rather than arrays of the elements. https://github.com/rails/rails/pull/1932 It''s a convenience method I''ve used for some time, mainly for debugging and logging, that I think belongs in core ActiveSupport with the other Enumerable additions. I''d appreciate feedback from the community on whether you agree on its usefulness, as well as the quality of the code, documentation, and tests. Thanks, Patrick -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/WqVJMsbN9uoJ. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
ivanpoval
2011-Jul-07 18:32 UTC
Re: Seeking Feedback on Pull Request 1932 (Added Enumerable#count_by and tests)
I''m agree that the functionality you suggested could be useful, but it seems to be very specific. We already could do smth. like: Model.all.group_by(&:attr_name).map{| x, y| {x, y.size} }, or even Model.group(:attr_name).count which will return the counts of the elements. -- Thanks, Ivan Povalyukhin On Jul 5, 11:31 am, Patrick Byrne <patrick.by...@tstmedia.com> wrote:> All, > > I created a pull request that adds Enumerable#count_by, which leverages > Enumerable#group_by to return the counts elements rather than arrays of the > elements. > > https://github.com/rails/rails/pull/1932 > > It''s a convenience method I''ve used for some time, mainly for debugging and > logging, that I think belongs in core ActiveSupport with the other > Enumerable additions. I''d appreciate feedback from the community on whether > you agree on its usefulness, as well as the quality of the code, > documentation, and tests. > > Thanks, > Patrick-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.