On Fri, Dec 30, 2011 at 12:47 AM, Nikolai Weibull <now / bitwi.se> wrote: > On Fri, Dec 30, 2011 at 00:26, Robert Klemme <shortcutter / googlemail.com>rote: > >> Easy way: > > I seem to have failed in communicating what IÃÎ after. wasnÃÕ after > different ways of implementing #hash, I was after the golden standard > of #hash implementations for value objects. o, again, whatÃÔ the > standard way of implementing #hash for value objects in Ruby? I have covered this a bit earlier: http://blog.rubybestpractices.com/posts/rklemme/018-Complete_Class.html Boils down to that the hash code should be derived from hash codes of all fields used as key fields in determining equivalence. > If there isnÃÕ one, perhaps one should be agreed upon? Why do you think a standard is needed? There are some well known requirements for good hash codes and how they are calculated and since most of the time Hash keys are from the same class whatever algorithm chosen works. > One suggestion would be the XOR of the hash values of the objectÃÔ > class and its instance variables. Not good, because then the same value in different fields has identical influence on the hash code. Consequently likelihood of collisions increases and thus performance of Hash storage and retrieval may decrease. > Another is the XOR of the hash value of the objectÃÔ class and the > hash value of an Array containing its instance variables. Better because that considers position. But still, I don't see the need. Note also that a proper Hash key usually should be immutable because changing them causes all sorts of trouble if not done carefully. And most of the time Hash keys are String, Symbol, Fixnum and the like - which all do have their #hash implementation already. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/