I am trying to initialise the hash pair and then look for the key using has.key in the hash pair value. I have given the condition see below:
if seen.has.key?(var)
<Execute Condition>
Could you shed lights on it how this actually works? I have tried looking around but still confuses me. Thanks
seen={}assigns an empty hashmap to the variableseenandhas.keycalls the methodkeyon the objecthas. Assuming thathasis a hashmap,keyis a method that takes a value as its argument and returns the key that maps to the given value in the hashmap.seen.has.key?(var)calls thehasmethod onseenand then calls thekey?method with the argumentvaron the result of that. Since hashmap objects don’t have ahasmethod, this will cause aNoMethodError.