Reordering hash in ruby. Making one key always last

Viewed 3090

Let's say I have a hash:

h = {:a=>1, :b=>3, :c=>2, :d=>4}

I want to sort it based on the keys, but I always want :c last. I really don't care the order of the others, as long as :c comes as the final one...

Is there a simple way to do this?

My idea was to get all the keys, remove :c, sort them and place them into a new array, then push :c into the array?

2 Answers
Related