Use activesupport's group_by on enumerable.