I have a list of Fruit structs called basket. Each Fruit struct has a name (a string) and a calories (an int
Fruit
basket
name
calories
The easy solution is
basket.sort_by { |f| [-f.calories, f.name] }
Of course, if this is the canonical sort order for fruit then it should be defined using the <=> method and with the Comparable module mixed into Fruit
<=>
Comparable