John Smith John Smith - 2 years ago 64
Ruby Question

Check if Hash is included in output

I am trying to check if a specific element is included in an output. I run:

results.include? {"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100}

but I get an error:

Syntax error, unexpected =>, expecting '}'

What did I do wrong?

ndn ndn
Answer Source

The problem is that the curly brackets in this case are interpreted as start of a block. Just put () around:

results.include?({"_id"=>{"car_id"=>44, "page"=>"5"}, "summarized_time"=>100})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download