Ruby | Enumerable map() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 function takes the object and the block which is for every enum, it also takes r1 and r2 which decides on the number of elements in the returned enumerable. Return Value: It returns a new array. Example #1: Ruby # Ruby program for map? method in Enumerable # returns enumerator enu1 = (2..6).map {|x| x * 10} Output: [20, 30, 40, 50, 60] Example #2: Ruby # Ruby program for map? method in Enumerable # returns an enumerator with nil enu1 = (2..6).map {} Output: [nil, nil, nil, nil, nil] 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 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 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 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 grep_v() function 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 1 min read Ruby | Enumerable grep_v() function 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 1 min read Like