Sort hash having duplicate values in ascending order of keys

Sunday, July 6, 2014

I have a hash that looks like this -

{"P1"=>108, "P6"=>50, "P3"=>50, "P5"=>40, "P2"=>40, "P4"=>40}

This is already sorted in the descending order of value.

I want the below output, wherein the original ordering(by value descending) is maintained, but for those keys that have the same values need to be sorted in ascending order of keys(for e.g., P3 comes before P6). I did have a look at the Hashes documentation and also googled around quite a bit, but I'm unable to find an easy way of doing this right with the approach that I could think of.

{"P1"=>108, "P3"=>50, "P6"=>50, "P2"=>40, "P4"=>40, "P5"=>40 }

Any pointers of approaching this in a simple way through ruby would be helpful.

Thank you.