Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

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






# Ruby code for eql?() method
  
# declaring array
a = [18, 22, 33, nil, 5, 6]
  
# declaring array
b = [1, 4, 1, 1, 88, 9]
  
# declaring array
c = [18, 22, nil, nil, 50, 6]
  
# eql?
puts "eql? : #{a.eql?(b)}\n\n"
  
# eql?
puts "eql? : #{b.eql?(c)}\n\n"
  
# eql?
puts "eql? : #{c.eql?(a)}\n\n"

Output :

eql? : false

eql? : false

eql? : false

Code #2 : Example for eql?() method




# Ruby code for eql?() method
  
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
b = ["cow", nil, "dog"]
  
# declaring array
c = ["cat", nil, nil]
  
# eql?
puts "eql? : #{a.eql?(b)}\n\n"
  
# eql?
puts "eql? : #{b.eql?(b)}\n\n"
  
# eql?
puts "eql? : #{c.eql?(a)}\n\n"

Output :

eql? : false

eql? : true

eql? : false



My Personal Notes arrow_drop_up
Recommended Articles
Page :