Ruby | Array one?() function
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 code for one?() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [2] # one? method example puts "one?() method form : #{a.one?()}\n\n" puts "one?() method form : #{b.one?()}\n\n" puts "one?() method form : #{c.one?()}\n\n" |
chevron_right
filter_none
Output :
one?() method form : false one?() method form : false one?() method form : true
Example #2 :
# Ruby code for one?() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cow"] # declaring array b = ["cow", nil, "dog"] # one? method example puts "one?() method form : #{a.one?()}\n\n" puts "one?() method form : #{b.one?()}\n\n" puts "one?() method form : #{c.one?()}\n\n" |
chevron_right
filter_none
Output :
one?() method form : false one?() method form : false one?() method form : true
Recommended Posts:
- Ruby | Array pop() function
- Ruby | Array max() function
- Ruby | Array min() function
- Ruby Array () function with example
- Ruby | Array zip() function
- Ruby | Array none?() function
- Ruby | Array take() function
- Ruby | Array map() function
- Ruby | Array &() function
- Ruby | Array <=> function
- Ruby | Array sort_by!() function
- Ruby | Array sort() function
- Ruby | Array length() function
- Ruby | Array reverse() function
- Ruby | Array replace() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

