Ruby | Array class eql?() operation
Last Updated :
08 Jan, 2020
Array#eql?() : eql?() is a Array class method which checks if the two arrays are equal or not.
Syntax: Array.eql?()
Parameter: Arrays to compare
Return: true – if the arrays are equal; otherwise false
Code #1 : Example for eql?() method
a = [ 18 , 22 , 33 , nil , 5 , 6 ]
b = [ 1 , 4 , 1 , 1 , 88 , 9 ]
c = [ 18 , 22 , nil , nil , 50 , 6 ]
puts "eql? : #{a.eql?(b)}\n\n"
puts "eql? : #{b.eql?(c)}\n\n"
puts "eql? : #{c.eql?(a)}\n\n"
|
Output :
eql? : false
eql? : false
eql? : false
Code #2 : Example for eql?() method
a = [ "abc" , "nil" , "dog" ]
b = [ "cow" , nil , "dog" ]
c = [ "cat" , nil , nil ]
puts "eql? : #{a.eql?(b)}\n\n"
puts "eql? : #{b.eql?(b)}\n\n"
puts "eql? : #{c.eql?(a)}\n\n"
|
Output :
eql? : false
eql? : true
eql? : false
Share your thoughts in the comments
Please Login to comment...