Hi Nikolai,
Writing a good hash function is actually language neutral. Some
literature suggested the following form:
p = <a big prime number> # 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 <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?
>
> If there isnÃÕ one, perhaps one should be agreed upon?
>
> One suggestion would be the XOR of the hash values of the objectÃÔ
> class and its instance variables.
>
> Another is the XOR of the hash value of the objectÃÔ class and the
> hash value of an Array containing its instance variables.
>