I have an array of Rails ActiveRecord models in which I need to group
by name and then sort by topic. For instance the initial array may
look like this (hopefully formatting comes out correctly):
Name Topic
News Politics
Sports Soccer
Finance Stocks
Finance Bonds
News World
News Entertainment
I will need to display the list as follows:
Name Topic
Finance Bonds
Stocks
News Entertainment
Politics
World
Sports Soccer
As you can see, we only display the name on the first entry of that
name. Sure, I can simply sort a one-dimensional array of these
objects and place the logic into the presentation such that it checks
if the name it is processing now differs from the last name. But that
didn’t see so clean. Is there a better Ruby way in doing this?