Ruby | Enumerator::Lazy#uniq function Last Updated : 12 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The uniq function in Ruby is used to find the unique set of elements from the given array. Syntax: xs.uniq Here, xs is a array of elements. Parameters: This function does not accept any parameters. Returns: the new set of unique values. Example 1: Ruby # Initialising an array with blocks as elements xs = [ [1, "GFG", 10], [1, "GFG", 20], [2, "Geeks", 30], [2, "Geeks", 40] ].to_enum.lazy # Calling uniq function for finding uniq element block us = xs.uniq{ |x| x[0] }.map{ |x| [x[0], x[1]] } # Produces result in blocks puts us.to_a.inspect Output: [[1, "GFG"], [2, "Geeks"]] Example 2: Ruby # Initialising an array ns = [1, 4, 6, 1, 2].to_enum.lazy # calling the uniq function for finding # uniq values form the above array puts ns.uniq.to_a.inspect Output: [1, 4, 6, 2] Comment More infoAdvertise with us Next Article Ruby | Enumerator::Lazy#uniq function K Kanchan_Ray Follow Improve Article Tags : Ruby Ruby-Methods Ruby Enumerable-class Similar Reads 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 | Enumerator::new function The new function in Ruby is used to create a new Enumerator object, which can be used as an Enumerable. Syntax: Enumerator.new Here, Enumerator is an object. Parameters: This function does not accept any parameters. Returns: the new set of values. Example 1: Ruby # Ruby program for Enumerator::new f 1 min read Ruby | Enumerator each function The Enumerator#each function in Ruby is used to Iterates over the object according to how this Enumerator was constructed and returns the object's values. Syntax: A.each { |key, value| print key + ' = ' + value + "\n" } Here, A is the initialized object. Parameters: This function accepts constituent 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 max() function The max() of enumerable is an inbuilt method in Ruby returns the maximum elements or an array containing the maximum N elements in the enumerable. When no block is given, it assumes all elements to be self comparable, but when the block is given then it is compared using . Syntax: enu.max(n) { |a, b 1 min read Like