3

尝试处理 ruby​​ 中的嵌套哈希时,出现此错误:

undefined method `has_key' for {"_l"=>{"or"=>"@`"}, "a"=>{}}:Hash (NoMethodError)

上面的'for'引用的东西不是...哈希吗?哈希没有 has_key?() 方法吗?这里发生了什么?

这是代码...谢谢:

$conditioning_environments = {
  "_l" =>
   {
    "or" => "@`"
   },
     "a" => {

   }
}
....
if $conditioning_environments["_"+graphemes[index+1]].has_key(g)
    ....
4

1 回答 1

13

您想要的方法是has_key?带问号。

您粘贴的代码段有问号,但错误表明有问题的代码中缺少它。

编辑:您从粘贴的代码段中删除了问号:p

于 2012-05-13T00:22:27.113 回答