Ruby | Array ==() method
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" |
chevron_right
filter_none
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" |
chevron_right
filter_none
Output :
comparison : false comparison : false comparison : true
Recommended Posts:
- Ruby | Array <<() method
- Ruby | Array Join (*) method
- Ruby | Array dig() operation
- Ruby | Array min() function
- Ruby | Array max() function
- Ruby | Array take() function
- Ruby | Array one?() function
- Ruby | Array &() function
- Ruby | Array any?() operation
- Ruby | Array map!() operation
- Add array elements in Ruby
- Ruby | Array <=> function
- Ruby | Array map() function
- How to initialize array in Ruby
- Ruby | Array pop() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


