Ruby | Array one?() function Last Updated : 26 Dec, 2022 Comments Improve Suggest changes Like Article Like Report 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 # 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" Output : one?() method form : false one?() method form : false one?() method form : true Example #2 : Ruby # Ruby code for one?() method # declaring array a = ["abc", "nil", "dog"] # declaring array b = ["cow"] # declaring array c = ["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" Output : one?() method form : false one?() method form : false one?() method form : true Comment More infoAdvertise with us Next Article Ruby | Array one?() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array Similar Reads Ruby | Array none?() function 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 # Ruby code for none?() method # declaring array a = [18, 22, 33, nil, 5, 6] # decla 1 min read Ruby | Array pop() function Array#pop() : pop() is a Array class method which checks removes the last element from the array and returns it. Syntax: Array.pop() Parameter: Array Return: removes the last element from the array and returns it. Example #1 : Ruby # Ruby code for pop() method # declaring array a = [18, 22, 33, nil, 1 min read Ruby | Array min() function Array#min() : min() is a Array class method which returns the minimum value in this array. Syntax: Array.min() Parameter: Array Return: the minimum value in this array. Example #1 : Ruby # Ruby code for min() method # declaring array a = %w[for geeks] # min method example puts "min() method for 1 min read Ruby | Array rindex() function Array#rindex() : rindex() is a Array class method which returns the index of the last object in the array. Syntax: Array.rindex() Parameter: Array Return: the index of the last object in the array. if not present then nil Example #1 : Ruby # Ruby code for rindex() method # declaring array a = [18, 2 1 min read Ruby | Array map() function Array#map() : map() is a Array class method which returns a new array containing the values returned by the block. Syntax: Array.map() Parameter: Array Return: a new array containing the values returned by the block. Example #1 : Ruby # Ruby code for map() method # declaring array a = [18, 22, 33, 3 2 min read Ruby | Array reject!() function Array#reject!() : reject!() is a Array class method which returns a new array containing the values which are not returned by the block. Syntax: Array.reject!() Parameter: Array Return: a new array containing the values not returned by the block. Example #1 : Ruby # Ruby code for reject!() method # 1 min read Ruby | Array length() function Array#length() : length() is a Array class method which returns the number of elements in the array. Syntax: Array.length() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for length() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array 1 min read Ruby | Array reject() function Array#reject() : reject() is a Array class method which returns new array containing the items in the array for which the given block is not true Syntax: Array.reject() Parameter: Array Return: new array containing the items in self for which the given block is not true Example #1 : Ruby # Ruby code 2 min read Ruby | Array pack() function Array#pack() : pack() is a Array class method which returns the contents of arr into a binary sequence according to the directives in aTemplateString Syntax: Array.pack() Parameter: Array Return: the contents of arr into a binary sequence according to the directives in aTemplateString Example #1 : R 1 min read Ruby | Array push() function Array#push() : push() is a Array class method which appends the given object(s) on to the end of this array. Syntax: Array.push() Parameter: Array Return: appends the given object(s) on to the end of this array. Example #1 : Ruby # Ruby code for push() method # declaring array a = [18, 22, 33, nil, 2 min read Like