所以让我改一下这个问题:
我有两个要比较的哈希值。在我的代码中的某个时刻,我得到了一个响应,例如..
@moves = {:wm01 => {:a1=>"O", :a2=>" ", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}
这对应于一个答案键哈希...
@anskey={
:wm01=>":c3",:wm02=>":c2",:wm03=>":c1",:wm04=>":b3",:wm05=>":b1",:wm06=>":a3",:wm07=>":a2",:wm08=>":a1",
:wm09=>":a3",:wm10=>":c1",:wm11=>":a1",:wm12=>":c3",:wm13=>":c3",:wm14=>":c1",:wm15=>":c3",:wm16=>":a1",
:wm17=>":b1",:wm18=>":b2",:wm19=>":b3",:wm20=>":a2",:wm21=>":b2",:wm22=>":b2",:wm23=>":c2",:wm24=>":b2"
}
在这种情况下,我需要迭代 @anskey where @moves.keys == @anskey.keys
(嗯。我可能刚刚回答了我自己的问题)
然后设置....
my_answer_is = @anskey.value
希望这更清楚。
原始“问题”如下:
辛苦了一天,屏幕有点疲劳……
我有这个...
str = [:wm24]
想说...
@anskey[:wm24]
这是错误的..
@anskey[str]
什么是正确的?
@anskey[?]