fork download
  1. #!/usr/bin/ruby -w
  2. # answer: http://o...content-available-to-author-only...e.jp/qa/q7067894.html
  3.  
  4. require 'pp'
  5.  
  6. h1 = {
  7. "user1" => {"a" => 10, "b" => 20, "c" => 30},
  8. "user2" => {"d" => 5, "e" => 8},
  9. "user3" => {"f" => 10, "g" => 5, "h" => 10}
  10. }
  11.  
  12. pp h1.sort_by{|key, value|value.values.inject :-}
Success #stdin #stdout 0.01s 5024KB
stdin
Standard input is empty
stdout
[["user1", {"a"=>10, "b"=>20, "c"=>30}],
 ["user3", {"f"=>10, "g"=>5, "h"=>10}],
 ["user2", {"d"=>5, "e"=>8}]]