Ruby | Array one?() function
Last Updated :
26 Dec, 2022
Array#one?() : one?() is a Array class method which checks whether the array is having only one array element.
Syntax: Array.one?() Parameter: Array Return: true – if array has only one element otherwise return false.
Example #1 :
Ruby
a = [ 18 , 22 , 33 , nil , 5 , 6 ]
b = [ 1 , 4 , 1 , 1 , 88 , 9 ]
c = [ 2 ]
puts "one?() method form :
puts "one?() method form :
puts "one?() method form :
|
Output :
one?() method form : false
one?() method form : false
one?() method form : true
Example #2 :
Ruby
a = ["abc", " nil ", "dog"]
b = ["cow"]
c = ["cow", nil , "dog"]
puts "one?() method form :
puts "one?() method form :
puts "one?() method form :
|
Output :
one?() method form : false
one?() method form : false
one?() method form : true
Share your thoughts in the comments
Please Login to comment...