1)Rubyコンソールでコーディングしたハッシュがあります
influencerHash
influencerHash.class => Hash
{"inf3"=>{"followingCount"=>256, "followersCount"=>80, "name"=>"Branislav Seslija", "score"=>10.4099998474121}, "inf2"=>{"followingCount"=>6, "followersCount"=>4, "name"=>"Greg Seslija", "score"=>29.8400001525879}, "inf1"=>{"followingCount"=>13, "followersCount"=>10, "name"=>"Amit Kumar", "score"=>30.6499996185303}}
2)ソートしましたが、ハッシュは配列に変換されます
sortHash = influencerHash.sort
sortHash.class => Array
[["inf1", {"followingCount"=>13, "followersCount"=>10, "name"=>"Amit Kumar", "score"=>30.6499996185303}], ["inf2", {"followingCount"=>6, "followersCount"=>4, "name"=>"Greg Seslija", "score"=>29.8400001525879}], ["inf3", {"followingCount"=>256, "followersCount"=>80, "name"=>"Branislav Seslija", "score"=>10.4099998474121}]]
3) 変換してハッシュに戻しましたが、並べ替えの結果が逆になっています (上記の配列と下のハッシュ結果を参照してください)。
sortHash = Hash[influencerHash.sort]
sortHash.class => Hash
{"inf3"=>{"followingCount"=>256, "followersCount"=>80, "name"=>"Branislav Seslija", "score"=>10.4099998474121}, "inf2"=>{"followingCount"=>6, "followersCount"=>4, "name"=>"Greg Seslija", "score"=>29.8400001525879}, "inf1"=>{"followingCount"=>13, "followersCount"=>10, "name"=>"Amit Kumar", "score"=>30.6499996185303}}
**
なぜこれが起こったのか、そして配列ではなくハッシュとして同じソートを取得するにはどうすればよいですか??
**