I have the following nested hash structure:
{12 => {:points=>0, :diff=>0},
1=> {:points=>18, :diff=>57},
4=>{:points=>12, :diff=>67},
5=>{:points=>9, :diff=>62}}
I'd like to sort it by points first (descending) and by diff second (ascending).
I'm able to sort it only by one of those values using:
my_hash.sort_by {|participant_id, values| values[:points] }.reverse.to_h
but I have been unable to find a way to sort it by both values.
I've tried using:
my_hash.sort_by {|participant_id, values| values[:diff] or values[:points] }.reverse.to_h
Most answers regarding hash sorting consider one value like this and other cases doesn't seem to fit my purpose. Could you help finding a solution?