Ruby | Enumerable to_a() function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 enu = (1..6) # Prints enu.to_a Output: [1, 2, 3, 4, 5, 6] Example #2: Ruby # Ruby program for to_a method in Enumerable # Initialize enu = {"gopal"=>10, "geeks"=>20} # Prints enu.to_a Output: [["gopal", 10], ["geeks", 20]] Comment More infoAdvertise with us Next Article Ruby | Enumerable to_a() function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Enumerable-class Similar Reads 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 Ruby | Enumerable any? function The any?() of enumerable is an inbuilt method in Ruby returns a boolean value if any of the object in the enumerable satisfies the given condition, else it returns false. Syntax enu.any? { |obj| block } or enu.any?(pattern) Parameters: The function takes two types of parameters, one is the object an 2 min read Ruby | Enumerable take() function The take() of enumerable is an inbuilt method in Ruby returns the first N elements from the enumerable. If it does not have N elements, then it returns the entire enum. Syntax: enu.take(n) Parameters: The function accepts N which specifies the number of elements to be returned. Return Value: It retu 1 min read Ruby | Enumerable sort() function The sort() of enumerable is an inbuilt method in Ruby returns an array which contains the enum items in a sorted order. The comparisons are done using operator or the optional block. The block must implement a comparison between a and b and return an integer less than 0 when b follows a, 0 when a an 1 min read Ruby | Enumerable sum() function The sum() of enumerable is an inbuilt method in Ruby returns the sum of all the elements in the enumerable. If a block is given, the block is applied to the enumerable, then the sum is computed. If the enumerable is empty, it returns init. Syntax: enu.sum { |obj| block } Parameters: The function acc 1 min read 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 uniq() function The uniq() of enumerable is an inbuilt method in Ruby returns an array removing all the duplicates in the given enum. Syntax: enu.uniq Parameters: The function accepts no parameter. Return Value: It returns an array. Example 1: Ruby # Ruby program for uniq method in Enumerable # Initialize enu = [1, 1 min read Ruby | Enumerable drop() function The drop() of enumerable is an inbuilt method in Ruby returns the rest elements in the enumerator after dropping the first N elements. Syntax: block.drop(N) Parameters: The function takes N which signifies the number of elements to be dropped. Return Value: It returns the rest elements after droppin 1 min read Ruby | Enumerable count() function The count() of enumerable is an inbuilt method in Ruby returns the number of elements in the enumerable, or the number of elements that are equal to a given element, or the number of items which satisfies the condition in the given block. Syntax: block.count { |obj| block } or block.count(element) P 1 min read Ruby | Enumerable cycle() function The cycle() of enumerable is an inbuilt method in Ruby calls block for each element of enum repeatedly the given numbers times or forever if none or nil is given. If a negative numbers is given or the collection is empty, it does nothing. It returns nil if the loop has finished without getting inter 1 min read Like