Hugh Sasse <hgs / dmu.ac.uk> writes: > On Thu, 15 Sep 2005, Christian Neukirchen wrote: > >> This seems to be the canonical way to define compund hashes: >> >> class Student >> def hash >> [@forename, @surname, @birth_dt, @picture, @coll_status].hash >> end >> end > > That does seem to preserve the properties I need for strings, and is > probably cheaper than MD5sums. >> > [...] >> >> Set uses a Hash to store the objects. >> >> That said, I think it would be nice to have something along this in >> the stdlib: >> >> class Student >> equal_compares :@forename, :@surname, :@birth_dt, :@picture, :@coll_status >> end >> >> Above call should result in appropriate definitions of ==, eql? and > > I don't know how it could know how to create the different > definitions correctly given a completely open spec as to what the > vars are. Well, you just list all instance variables that define the object... if they are the same, the objects are eql?. >> hash. (Something like "ordered_by" would be pretty useful too.) > > I think that could be tricky too. In the end, [*fields] <=> [*other.fields] does the job. > Thank you. > Hugh > -- Christian Neukirchen <chneukirchen / gmail.com> http://chneukirchen.org