Ruby | Enumerable max() function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The max() of enumerable is an inbuilt method in Ruby returns the maximum elements or an array containing the maximum N elements in the enumerable. When no block is given, it assumes all elements to be self comparable, but when the block is given then it is compared using . Syntax: enu.max(n) { |a, b| block } Parameters: The function takes two optional parameters n and block. N signifies the number of maximum elements and block determines the comparison property. Return Value: It returns a max element or an array containing N max elements. Example #1: Ruby # Ruby program for max method in Enumerable # Initialize enu1 = (2..6) # Prints puts enu1.max p enu1.max(2) Output: 6 [6, 5] Example #2: Ruby # Ruby program for max method in Enumerable # Initialize enu1 = [10, 17, 9, 10, 100, 34] # Prints puts enu1.max { |a, b| a<=>b} p enu1.max(2){ |a, b| a<=>b} Output: 100 [100, 34] Comment More infoAdvertise with us Next Article Ruby | Enumerable max() function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Enumerable-class Similar Reads Ruby | Enumerable map() function The map() of enumerable is an inbuilt method in Ruby returns a new array with the results of running block once for every element in enum. The object is repeated every time for each enum. In case no object is given, it return nil for each enum. Syntax: (r1..r2).map { |obj| block } Parameters: The fu 1 min read Ruby | Enumerable max_by() function The max_by() of enumerable is an inbuilt method in Ruby returns an array of maximum elements which satisfies the condition of the given block. It returns an enumerator when no block is given. Syntax: enu.max_by(n) {|obj| block} Parameters: The function takes two parameters n and block. N signifies t 1 min read Ruby | Enumerable minmax() function The minmax() of enumerable is an inbuilt method in Ruby returns an array containing two elements. It contains the minimum and the maximum value in the enumerable. The first form assumes all objects implement Comparable whereas the second uses the block to return a b. Syntax: enu.minmax { |a, b| bloc 1 min read Ruby | Enumerable min() function The min() of enumerable is an inbuilt method in Ruby returns the minimum elements or an array containing the minimum N elements in the enumerable. When no block is given, it assumes all elements to be self comparable, but when the block is given then it is compared using . Syntax: enu.min(n) { |a, b 1 min read Ruby | Enumerable minmax_by() function The minmax_by() of enumerable is an inbuilt method in Ruby returns an array containing two elements. It contains the minimum and the maximum value in the enumerable according to the condition in the block. Syntax: enu.minmax_by { |obj| block } Parameters: The function takes an optional block. Return 1 min read Ruby | Enumerable flat_map function The flat_map() of enumerable is an inbuilt method in Ruby returns a new array with the concatenated results of running block once for every element in enum. In case no block is given, an enumerator is returned instead. Syntax: block.flat_map { |obj| block } Parameters: The function takes the block a 1 min read Ruby | Enumerable min_by() function The min_by() of enumerable is an inbuilt method in Ruby returns an array of minimum elements which satisfies the condition of the given block. It returns an enumerator when no block is given. Syntax: enu.min_by(n) { |obj| block } Parameters: The function takes two parameters n and block. N signifies 1 min read Ruby | Enumerable grep() function The grep() of enumerable is an inbuilt method in Ruby returns an array of elements which contain every (element == pattern), of all the elements in the pattern. If the optional block is not given, then it returns an array containing the elements in that pattern. Syntax: enu.grep(pattern) { |obj| blo 1 min read Ruby | Enumerable none?() function The none?() of enumerable is an inbuilt method in Ruby returns a boolean value true if none of the objects in the enumerable satisfies the given condition, else it returns false. It compares all the elements with the pattern and returns true if none of them matches with the pattern. Syntax enu.none? 2 min read Ruby | Enumerable member? function The member?() of enumerable is an inbuilt method in Ruby returns a boolean value. It returns true if the enumerable contains the given elements, or else it returns false. Syntax: enu.member?(el) Parameters: The function takes an element which is to be checked for. Return Value: It returns a boolean 1 min read Like