{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/19725","labels_url":"https://api.github.com/repos/rails/rails/issues/19725/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/19725/comments","events_url":"https://api.github.com/repos/rails/rails/issues/19725/events","html_url":"https://github.com/rails/rails/pull/19725","id":67729427,"number":19725,"title":"Enumerable#count by","user":{"login":"baweaver","id":979723,"avatar_url":"https://avatars.githubusercontent.com/u/979723?v=3","gravatar_id":"","url":"https://api.github.com/users/baweaver","html_url":"https://github.com/baweaver","followers_url":"https://api.github.com/users/baweaver/followers","following_url":"https://api.github.com/users/baweaver/following{/other_user}","gists_url":"https://api.github.com/users/baweaver/gists{/gist_id}","starred_url":"https://api.github.com/users/baweaver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baweaver/subscriptions","organizations_url":"https://api.github.com/users/baweaver/orgs","repos_url":"https://api.github.com/users/baweaver/repos","events_url":"https://api.github.com/users/baweaver/events{/privacy}","received_events_url":"https://api.github.com/users/baweaver/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-11T03:50:44Z","updated_at":"2015-04-11T04:52:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/19725","html_url":"https://github.com/rails/rails/pull/19725","diff_url":"https://github.com/rails/rails/pull/19725.diff","patch_url":"https://github.com/rails/rails/pull/19725.patch"},"body":"Adds the ``Enumerable#count_by`` method.\r\n\r\nA common idiom I've seen out and about is trying to get a grouped count of object properties. For instance, we use AWS quite a bit, so we might want to know:\r\n\r\n```ruby\r\nAmazonInstance.where(state: 'running').count_by(&:instance_type)\r\n# => {'m1.xlarge' => 999, 't1.micro' => 999}\r\n```\r\n\r\nor in more normal cases you might want some demographics on your users:\r\n```ruby\r\nUser.joins(:address).where(address: {state: 'CA'}).count_by { |user| user.address.zip_code }\r\n```\r\n\r\nAdmittedly this may be better served in an sql context"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/91761031","html_url":"https://github.com/rails/rails/pull/19725#issuecomment-91761031","issue_url":"https://api.github.com/repos/rails/rails/issues/19725","id":91761031,"user":{"login":"baweaver","id":979723,"avatar_url":"https://avatars.githubusercontent.com/u/979723?v=3","gravatar_id":"","url":"https://api.github.com/users/baweaver","html_url":"https://github.com/baweaver","followers_url":"https://api.github.com/users/baweaver/followers","following_url":"https://api.github.com/users/baweaver/following{/other_user}","gists_url":"https://api.github.com/users/baweaver/gists{/gist_id}","starred_url":"https://api.github.com/users/baweaver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baweaver/subscriptions","organizations_url":"https://api.github.com/users/baweaver/orgs","repos_url":"https://api.github.com/users/baweaver/repos","events_url":"https://api.github.com/users/baweaver/events{/privacy}","received_events_url":"https://api.github.com/users/baweaver/received_events","type":"User","site_admin":false},"created_at":"2015-04-11T04:52:40Z","updated_at":"2015-04-11T04:52:40Z","body":"I'd almost be tempted to gemify some of it into a Statistics package as well."}}