Ruby | Enumerable grep_v() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The grep_v() of enumerable is an inbuilt method in Ruby returns an array of elements which contain every (element != pattern). If the optional block is not given, then it returns an array which does not contain the elements in that pattern. Syntax: enu.grep_v(pattern) { |obj| block } Parameters: The function takes a pattern and an optional block. Return Value: It returns either an array of boolean values or an array containing the elements that are not contained in the pattern. Example #1: Ruby # Ruby program for grep_v method in Enumerable # Initialize enu = (1..10) # Prints enu.grep_v (3..5) Output: [1, 2, 6, 7, 8, 9, 10] Example #2: Ruby # Ruby program for grep_v method in Enumerable # Initialize enu = (1..10) # Prints enu.grep_v (3..5) { |obj| obj + 10 } Output: [11, 12, 16, 17, 18, 19, 20] Comment More infoAdvertise with us Next Article Ruby | Enumerable grep() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Enumerable-class Similar Reads 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 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 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 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 group_by() function The group_by() of enumerable is an inbuilt method in Ruby returns an hash where the groups are collectively kept as the result of the block after grouping them. In case no block is given, then an enumerator is returned. Syntax: enu.group_by { |obj| block } Parameters: The function takes an optional 1 min read Ruby | Enumerable group_by() function The group_by() of enumerable is an inbuilt method in Ruby returns an hash where the groups are collectively kept as the result of the block after grouping them. In case no block is given, then an enumerator is returned. Syntax: enu.group_by { |obj| block } Parameters: The function takes an optional 1 min read Like