Ruby | Array max() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#max() : max() is a Array class method which returns the maximum value in this array. Syntax: Array.max() Parameter: Array Return: the maximum value in this array. Example #1 : Ruby # Ruby code for max() method # declaring array a = %w[for geeks] # max method example puts "max() method form : #{a.max()}\n\n" puts "max() method form : #{a.max(2)}\n\n" Output : max() method form : geeks max() method form : ["geeks", "for"] Example #2 : Ruby # Ruby code for max() method # declaring array a = %w[hi I can code for geeks] # max method example puts "max() method form : #{a.max(4)}\n\n" puts "max() method form : #{a.max(1)}\n\n" Output : max() method form : ["hi", "geeks", "for", "code"] max() method form : ["hi"] Comment More infoAdvertise with us Next Article Ruby | Array max() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads 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 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 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 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 <=> function Array#() : () is an Array class method which performs the comparison between the two arrays. Syntax: Array.() Parameter: Array for the comparison Return: 1 : if a > b -1 : if a < b 0 : if a = b Example #1 : Ruby # Ruby code for <=>() method # checking equality # declaring arrays a = [18, 2 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 take() function Array#take() : take() is a Array class method which returns the number of elements in the array. Syntax: Array.take() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for take() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 1 min read Ruby | Array class last() function last() is a Array class method which returns the last element of the array or the last 'n' elements from the array. The first form returns nil, If the array is empty . Syntax: Array.last() Parameter: Array n - no. of elements Return: last element of the array or the last 'n' elements from the array 1 min read Ruby | Array assoc() function The assoc() function in Ruby is used to search through an array of arrays whose first element is compared with the index of the function and return the contained array if match found otherwise return either nil or vacant. Syntax: Array.assoc(Object) Here Array is the array of arrays. Parameters: Obj 2 min read Ruby | Array slice!() function Array#slice!() : slice!() is a Array class method which seletes the element(s) given by an index or by a range. Syntax: Array.slice!() Parameter: Array Return: Deletes the elements given by an index or by a range. Example #1 : Ruby # Ruby code for slice!() method # declaring array a = [18, 22, 33, n 2 min read Like