Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Array none?() function

  • Last Updated : 06 Dec, 2019

Array#none?() : none?() is a Array class method which checks whether the array is empty or not.

Syntax: Array.none?()

Parameter: Array

Return: true – if array has no elements otherwise return false

Example #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"

Output :

none?() method form : false

none?() method form : false

none?() method form : true

Example #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"

Output :

none?() method form : false

none?() method form : false

none?() method form : true




My Personal Notes arrow_drop_up
Recommended Articles
Page :