Ruby program to compare two hash collections using '==' operator

bookmark


hash1 = {"101" => "Amit", "102" => "Arun", "103" => "Sumit"};
hash2 = {"101" => "Amit", "102" => "Ankit", "103" => "Sumit"};
hash3 = {"101" => "Amit", "102" => "Arun", "103" => "Sumit"};

if hash1==hash2
    print "hash1 and hash2 are equal\n";
else
    print "hash1 and hash2 are not equal\n";
end

if hash1==hash3
    print "hash1 and hash3 are equal\n";
else
    print "hash1 and hash3 are not equal\n";
end

 


Output:

hash1 and hash2 are not equal
hash1 and hash3 are equal