The source code to compare two hash collections using the "==" operator is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
# Ruby program to compare two hash collections
# using '==' operator
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
Explanation:
In the above program, we created 3 hash collections hash1, hash2, hash3. Then we compared created hash collections using the "==" operator and printed the appropriate message.
Program/Source Code:
The source code to compare two hash collections using the "==" operator is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
Output:
Explanation:
In the above program, we created 3 hash collections hash1, hash2, hash3. Then we compared created hash collections using the "==" operator and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer