what is the best way to make such deep check:
{:a => 1, :b => {:c => 2, :f => 3, :d => 4}}.include?({:b => {:c => 2, :f => 3}}) #=> true
thanks
what is the best way to make such deep check:
{:a => 1, :b => {:c => 2, :f => 3, :d => 4}}.include?({:b => {:c => 2, :f => 3}}) #=> true
thanks
I like this one:
I think I see what you mean from that one example (somehow). We check to see if each key in the subhash is in the superhash, and then check if the corresponding values of these keys match in some way: if the values are hashes, perform another deep check, otherwise, check if the values are equal:
You can see how this works because the
if
statement returns a value: the last statement evaluated (I did not use the ternary conditional operator because that would make this far uglier and harder to read).