红宝石 |数组 ==() 方法
Array#==()是一个 Array 类方法,用于执行两个数组之间的比较。它检查两个数组是否相等。
Syntax: Array.==()
Parameter: Array for the comparison
Return: true : if arrays are equal
false : if arrays are not equal
示例 #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"
输出 :
comparison : true
comparison : false
comparison : false
示例 #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"
输出 :
comparison : false
comparison : false
comparison : true