ADVERTISEMENT
ADVERTISEMENT

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

Ruby Example: Write a program to compare two hash collections using '==' operator.
Submitted by Nidhi, on February 14, 2022

Problem Solution:

In this program, we will create three hash collections. Then we will compare created collections using the "==" operator.

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.

# 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.

Ruby Hashes Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.