Ruby | Enumerable each_slice() function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 specifies the number of elements to take in a single slice. Return Value: It returns the elements in N slices. Example 1: Ruby # Ruby program for each_slice method in Enumerable # Initialize enu = (1.. 5) # returns slice enu.each_slice(2){|obj| p obj} Output: [1, 2] [3, 4] [5] Example 2: Ruby # Ruby program for each_slice method in Enumerable # Initialize enu = (1..10) # returns each element enu.each_slice(4) Output: Enumerator: 1..10:each_slice(4) Comment More infoAdvertise with us Next Article Ruby | Enumerable each_slice() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Enumerable-class Similar Reads Ruby | Enumerable select() function The select() 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.select { |obj| block } Parameters: The function takes a block whose condition is used to find the e 1 min read Ruby | Enumerable each_cons() function The each_cons() of enumerable is an inbuilt method in Ruby iterates for consecutive N elements starting from each element every time. If no block is given, it returns the enumerator. Syntax: enu.each_cons(N) { |obj| block } Parameters: The function takes the block which is used to check the conditio 1 min read Ruby | Enumerable to_a() function The to_a() of enumerable is an inbuilt method in Ruby returns an array containing all the items of the enumerable. Syntax: enu.to_a() Parameters: The function does not accepts any parameter. Return Value: It returns an array. Example #1: Ruby # Ruby program for to_a method in Enumerable # Initialize 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 all? function The all?() of enumerable is an inbuilt method in Ruby returns a boolean value true if all the objects in the enumerable satisfies the given condition, else it returns false. If a pattern is given, it compares with the pattern, and returns true if all of them are equal to the given pattern, else it r 2 min read Like