In this case, presumably you could just do
@posts.group_by(&:author_id)
More generally, you can pass a group_by block, so if you need to group by some arbitrary logic:
@posts.group_by { |post|
... some code returning a value to group this post by ...
}
, , , , group_by , , , "" , , , , group_by.