Ruby | Enumerable find_index() function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The find_index() of enumerable is an inbuilt method in Ruby returns the index of the item which returns true for the given condition in the block, or the index of the item which is equal to the given value. If no block is given, then it returns an enumerator. If the values is not present in the enumerable, then it returns nil. Syntax: enu.find_index { |obj| block } or enu.find (val) Parameters: The function takes a block whose condition is used to find the first element which is true or takes the value whose first occurrence is to be searched for. Return Value: It returns the index. Example 1: ruby # Ruby program for find_index method in Enumerable # Initialize enu = [8, 9, 10, 14] # Prints enu.find_index { |obj| obj % 2 == 1} Output: 1 Example 2: ruby # Ruby program for find_index method in Enumerable # Initialize enu = (1..6) # Prints puts enu.find_index(4) puts enu.find_index(7) Output: 3 nil Comment More infoAdvertise with us Next Article Ruby | Enumerable find_index() function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Enumerable-class Similar Reads Ruby | Enumerable find() function The find() of enumerable is an inbuilt method in Ruby returns the first element which satisfies the given condition in the block. If there is no block, then it returns the enumerator itself. Syntax: block.find { |obj| block } Parameters: The function takes the block according to which the first whic 1 min read Ruby | Enumerable include?() function The include?() 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.include?(el) Parameters: The function takes an element which is to be checked for. Return Value: It returns a boolea 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 find_all() function The find_all() of enumerable is an inbuilt method in Ruby returns the items in the enumerable which satisfies the given condition in the block. It returns an enumerator if no block is given. Syntax: enu.find_all { |obj| block } Parameters: The function takes a block whose condition is used to find 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 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 first() function The first() of enumerable is an inbuilt method in Ruby returns the first N elements or the first element of the enumerable. If there is no first element, it returns nil. If there are less than N elements, then it returns all the elements. Syntax: enu.first(N) Parameters: The function takes N which s 1 min read Ruby | Enumerable max() function 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 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 Like