Hugh Sasse <hgs / dmu.ac.uk> writes:

>> if so maybe something like
>>
>>  class Student
>>    def hash
>>      %w( forename surname birth_dt picture coll_status).map{|m| send
>> %m}.join.hash
>>    end
>>  end
>
> Yes, that seems safer

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       

>> it sure seems odd that set doesn't use 'eql?' or '==' up front though doesn't
>> it?
>
> Probably a reason I don't know about.  The Pickaxe II says it uses
> eql? and hash (p731) but doesn't say where. 

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
hash.  (Something like "ordered_by" would be pretty useful too.)

> Hugh.
-- 
Christian Neukirchen  <chneukirchen / gmail.com>  http://chneukirchen.org