From: Michael Guterl Date: 2008-09-14T20:21:37+09:00 Subject: Re: getting an array of unique objects of a class i wrote On Sun, Sep 14, 2008 at 7:08 AM, Adam Akhtar wrote: > Hi Ive done some searching on this but couldnt find an answer that was > either totally appropriate or one that i could understand ;> (some > advanced stuff going on). > > So if i have a class with two variables (strings) like this > > class thing > attr_accessor :name :job > end > > and i want to ensure that if i have an array of these objects there will > be no duplicates. A duplicate would be where both the name and job are > the same in both objects. > > I tried using uniq! but it didnt work. Not sure why (can someone explain > that). > > Ive heard of set, could that be used in this case to prevent duplicates > being added? You need to implement Thing#eql? and Thing#hash in order for a Array#uniq, Set, or Hash to function as you expect.