From: Pit Capitain Date: 2007-01-30T17:21:27+09:00 Subject: Re: Sane #hash implementation? Shot (Piotr Szotkowski) schrieb: > Eric Hodel: > >> On Jan 29, 2007, at 14:38, Shot (Piotr Szotkowski) wrote: > >>> I�m stuck when it comes to Block#hash, though; I need these to be true: >>> Block.new.hash == Block.new.hash >>> Block.new([1,2]).hash == Block.new([1,2]).hash > >> Try: > >> class Block >> def hash >> to_a.hash >> end >> end > > Thanks a lot, Eric! This is the �d�oh!� solution I was looking for. :) Shot, you should be aware that this works for your example given above, but not for the following: Block.new([1,12]).hash # => 57 Block.new([12,1]).hash # => 23 If this is a problem, you have to change the implementation to class Block def hash sort.hash end end Regards, Pit