I want to remove duplicate elements inside an Array object. Best explained by example.
I have the following Array
entries = ["abc", "ab", "c", "cd"]
I need a method that will clear it by removing duplicate elements from elements in an Array and return an Array that has one element for each unique element.
So here is this method that I wrote for this:
class Array def clean_up() self.join(" ").split(" ").uniq end end
So, now when I call entries.clean_up , I get the following as a result:
["a", "b", "c", "d"]
This is exactly the result I want, but is there a more elegant way to do this in Ruby?
source share