Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `has_key'?

Tags:

ruby

hash

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)
    ....
like image 501
Walrus the Cat Avatar asked Sep 09 '26 11:09

Walrus the Cat


1 Answers

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

like image 106
x1a4 Avatar answered Sep 11 '26 19:09

x1a4