Ruby | Array max() function Last Updated : 06 Dec, 2019 Summarize Comments Improve Suggest changes Share 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 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 Like