📜  红宝石 |数组无?()函数

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

红宝石 |数组无?()函数

Array#none?() : none?()是一个 Array 类方法,用于检查数组是否为空。

示例 #1:

# Ruby code for none?() method
  
# declaring array
a = [18, 22, 33, nil, 5, 6]
  
# declaring array
b = [1, 4, 1, 1, 88, 9]
  
# declaring array
c = []
  
# none? method example
puts "none?() method form : #{a.none?()}\n\n"
  
puts "none?() method form : #{b.none?()}\n\n"
  
puts "none?() method form : #{c.none?()}\n\n"

输出 :

none?() method form : false

none?() method form : false

none?() method form : true

示例 #2:

# Ruby code for none?() method
  
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
c = [nil]
  
# declaring array
b = ["cow", nil, "dog"]
  
  
# none? method example
puts "none?() method form : #{a.none?()}\n\n"
  
puts "none?() method form : #{b.none?()}\n\n"
  
puts "none?() method form : #{c.none?()}\n\n"

输出 :

none?() method form : false

none?() method form : false

none?() method form : true