Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Ruby | Enumerable uniq() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 program for uniq method in Enumerable
   
# Initialize 
enu = [1, 1, 2, 2, 4, 4]
   
# Prints 
enu.uniq

Output:

[1, 2, 4]

Example 2:




# Ruby program for uniq method in Enumerable
   
# Initialize 
enu = ['a', 'b', 'a', 'c']
   
# Prints 
enu.uniq

Output:

["a", "b", "c"]
My Personal Notes arrow_drop_up
Last Updated : 05 Dec, 2019
Like Article
Save Article
Similar Reads