Seeking Feedback on Pull Request 1932 (Added Enumerable#count_by and tests)

17 views
Skip to first unread message

Patrick Byrne

unread,
Jul 5, 2011, 2:31:32 PM7/5/11
to rubyonra...@googlegroups.com
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

ivanpoval

unread,
Jul 7, 2011, 2:32:01 PM7/7/11
to Ruby on Rails: Core
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
Reply all
Reply to author
Forward
0 new messages