Ruby | Enumerable each_witth_object() function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The each_with_object() of enumerable is an inbuilt method in Ruby iterates for every object and returns the initial object. It returns the enumerator, if no block is given. Syntax: enu.each_with_object(obj) { |obj| block } Parameters: The function takes the block which is used to initialise the initial object. Return Value: It returns the enumerator, if no block is given, else it returns the initial object. Example 1: ruby # Ruby program for each_with_object method in Enumerable # Initialize enu = [7, 9, 10] # Prints each with object enu.each_with_object([]) { |obj, el| el << obj+10 } Output: [17, 19, 20] Example 2: ruby # Ruby program for each_with_object method in Enumerable # Initialize enu = [7, 9, 10] # Prints each with object enu.each_with_object([]) Output: Enumerator: [7, 9, 10]:each_with_object([]) Comment More infoAdvertise with us Next Article Ruby | Enumerable each_witth_object() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Enumerable-class Similar Reads Ruby | Enumerator each_with_object function The each_with_object function in Ruby is used to Iterate the given object's each element. Syntax: A.each_with_object({}) Here, A is the initialised object. Parameters: This function does not accept any parameters. Returns: the new set of values. Example 1: Ruby # Calling the .each_with_object functi 1 min read Ruby | Enumerable each_with_index() function The each_with_index() of enumerable is an inbuilt method in Ruby hashes the items in the enumerable according to the given block. In case no block is given, then an enumerator is returned. Syntax: enu.each_with_index { |obj| block } Parameters: The function takes the block which is used to initialis 1 min read Ruby | Enumerable each_slice() function The each_slice() of enumerable is an inbuilt method in Ruby iterates for each range of N elements and prints them. If no block is given, then it returns the enumerator. Syntax: enu.each_slice(N) { |obj| block } Parameters: The function takes the block which is used to check the condition and N which 1 min read Ruby | Enumerator each_with_index function The each_with_index function in Ruby is used to Iterate over the object with its index and returns value of the given object. Syntax: A.each_with_index Here, A is the initialised object. Parameters: This function does not accept any parameters. Returns: the value of the given object. Example 1: Ruby 1 min read Ruby | Enumerable reject() function The reject() of enumerable is an inbuilt method in Ruby returns the items in the enumerable which does not satisfies the given condition in the block. It returns an enumerator if no block is given. Syntax: enu.reject { |obj| block } Parameters: The function takes a block whose condition is used to f 1 min read Like