Open In App

Ruby | Array none?() function

Improve
Improve
Like Article
Like
Save
Share
Report

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



Last Updated : 06 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads