Ruby 数组==()方法
Array#==() 是一个数组类方法,它在两个数组之间进行比较。它检查这两个数组是否相等。
语法。Array.==()
参数。用于比较的数组
返回:true : 如果数组相等
false : 如果数组不相等
例子 #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