Ruby 数组none?()函数

Ruby 数组none?()函数

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

语法。Array.none?()

参数。数组

返回:true – 如果数组没有元素,则返回false。

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程