From: Yong Li Date: 2011-12-30T12:23:24+09:00 Subject: Re: What’s the standard way of implementing #hash for value objects in Ruby? Hi Nikolai, Writing a good hash function is actually language neutral. Some literature suggested the following form: p = # e.g. p = 31 hash = 1 for each object you will use in equal do hash = hash * p + object.hash end I am not sure if this fits your desire of a ruby-flavor hash implementation, but I do use this consistently in all my Java projects. On Fri, Dec 30, 2011 at 7:47 AM, Nikolai Weibull wrote: > On Fri, Dec 30, 2011 at 00:26, Robert Klemme wrote: > >> Easy way: > > I seem to have failed in communicating what I’m after.  I wasn’t after > different ways of implementing #hash, I was after the golden standard > of #hash implementations for value objects.  So, again, what’s the > standard way of implementing #hash for value objects in Ruby? > > If there isn’t one, perhaps one should be agreed upon? > > One suggestion would be the XOR of the hash values of the object’s > class and its instance variables. > > Another is the XOR of the hash value of the object’s class and the > hash value of an Array containing its instance variables. >