Stop duplicates from being added to an array of Ruby objects

Posted by Dom on Stack Overflow See other posts from Stack Overflow or by Dom
Published on 2010-05-10T16:10:22Z Indexed on 2010/05/10 16:34 UTC
Read the original article Hit count: 204

Filed under:
|

how can I eliminate duplicate elements from an array of ruby objects using an attribute of the object to match identical objects.

with an array of basic types I can use a set..

eg.

array_list = [1, 3, 4 5, 6, 6]
array_list.to_set 
=> [1, 2, 3, 4, 5, 6]

can I adapt this technique to work with object attributes?

thanks

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails