×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to compare two arrays using the eql?() method

Last Updated : December 15, 2025

Problem Solution

In this program, we will create three arrays of integers then we will compare arrays using the eql?() method and print the appropriate message.

Program/Source Code

The source code to compare two arrays using the eql?() method is given below. The given program is compiled and executed successfully.

# Ruby program to compare two arrays 
# using eql?() method

arr1 = [10,20,30,20,50,30];
arr2 = [10,50,30,40,60,70];
arr3 = [10,20,30,20,50,30];

if arr1.eql?(arr2)
    print "arr1 and arr2 are equal.\n";
else
    print "arr1 and arr2 are not equal.\n";
end

if arr1.eql?(arr3)
    print "arr1 and arr3 are equal.\n";
else
    print "arr1 and arr3 are not equal.\n";
end

Output

arr1 and arr2 are not equal.
arr1 and arr3 are equal.

Explanation

In the above program, we created 3 arrays arr1, arr2, arr3 with some elements. Then we compared arrays using the eql?() method and printed the appropriate message.

Ruby Arrays Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.