📜  红宝石 |数组 ==() 方法

📅  最后修改于: 2022-05-13 01:55:49.073000             🧑  作者: Mango

红宝石 |数组 ==() 方法

Array#==()是一个 Array 类方法,用于执行两个数组之间的比较。它检查两个数组是否相等。

示例 #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