When trying to deal with a nested hash in ruby, I’m getting this error:
undefined method `has_key' for {"_l"=>{"or"=>"@`"}, "a"=>{}}:Hash (NoMethodError)
isn’t the thing referenced by ‘for’ above… a hash? don’t hashes have the has_key?() method? what’s going on here?
Here’s the code… thanks:
$conditioning_environments = {
"_l" =>
{
"or" => "@`"
},
"a" => {
}
}
....
if $conditioning_environments["_"+graphemes[index+1]].has_key(g)
....
The method you want is
has_key?with a question mark.The snippet you pasted has the question mark, but error indicates it’s missing in the problematic code.
EDIT: you removed the question mark from the pasted snippet :p