From: Radek Skokan Date: 2006-04-11T19:28:51+09:00 Subject: Duplicity in Set ------=_Part_3234_18387969.1144751328644 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I have a Set which should contains elements of my object Component. The component class implements method hash. I'm gathering data, createing Componets from them and storing it into the Set. It's a Set just to prevent duplicates. But finally the Set contains duplicate elemets -- with the same hash value. Few snippets from the code: $components =3D Set.new # declaration of the Set variable .... then some addings to $components ... $components.each {|c| puts(c.name + ', class:' + c.class.name + ', hash:' + c.hash.to_s)} And it prints: OR-copm2.2, class:Component, hash:304328379 OR-copm2.2, class:Component, hash:304328379 The Component class is defined in this way: Class Component attr_reader :attributes, :name, :subcomponents attr_writer :attributes # array of Attribute objects def assembly? @subcomponents.length !=3D 0 end def object_id @name.object_id end def hash @name.hash end def initialize(name) @name =3D name @attributes =3D Hash.new @subcomponents =3D Array.new end end What am I doing wrong? Thanks, Radek ------=_Part_3234_18387969.1144751328644--