我有以下哈希值:
{"match"=>0, "reach"=>1, "safe"=>2, "undecided"=>3}
我想更改如下顺序:
{"reach"=>1, "match"=>0, "safe"=>2, "undecided"=>3}
最有效的解决方案是什么?
答案 0 :(得分:5)
{"match"=>0, "reach"=>1, "safe"=>2, "undecided"=>3}
.slice("reach", "match", "safe", "undecided")
# => {"reach"=>1, "match"=>0, "safe"=>2, "undecided"=>3}