Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Array ==() method

  • Last Updated : 07 Jan, 2020

Array#==() is an Array class method which performs the comparison between the two arrays. It checks whether the two arrays are equal or not.

Syntax: Array.==()

Parameter: Array for the comparison

Return: true : if arrays are equal
false : if arrays are not equal

Example #1 :






# Ruby code for ==() method
# checking equality
   
# differencing arrays
a = [18, 22, 33, 4, 5, 6]
   
# differencing arrays
b = [18, 22, 33, 4, 5, 6]
   
# differencing arrays
c = [18, 22, 33, 40, 50, 6]
   
# checking array equality
puts "comparison : #{a == b}\n\n"
   
# checking array equality
puts "comparison : #{a == c}\n\n"
   
# checking array equality
puts "comparison : #{b == c}\n\n"

Output :

comparison : true

comparison : false

comparison : false

Example #2 :




# Ruby code for ==() method
# checking equality
   
# differencing arrays
a = ["abc", "xyz", "dog"]
   
# differencing arrays
b = ["cat", "cat", "dog"]
   
# differencing arrays
c = ["cat", "cat", "dog"]
   
# checking array equality
puts "comparison : #{a == b}\n\n"
   
# checking array equality
puts "comparison : #{a == c}\n\n"
   
# checking array equality
puts "comparison : #{b == c}\n\n"

Output :

comparison : false

comparison : false

comparison : true



My Personal Notes arrow_drop_up
Recommended Articles
Page :