In some scenario of Ruby 1.8. If I have a hash
# k is name, v is order foo = { \"Jim\" => 1, \"bar\" => 1, \"joe\" => 2} sorted_by_values = foo.sort
Hashes are unordered by definition. There can be no such thing as a sorted Hash. Your best bet is probably to extract the keys from the sorted array using collect and then do a join on the result
sortedByValues = foo.sort {|a, b| a[1] <==> b[1]} sortedByValues.collect { |a| a[0] }.join ','