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}}
**
为什么会发生这种情况,我将如何获得与 Array 中相同但作为 Hash 的排序?
**