You can do this with [`group_by`](http://ruby-doc.org/core-2.0/Enumerable.html#method-i-group_by).