Hi Nikolai,

Writing a good hash function is actually language neutral. Some
literature suggested the following form:

    p =3D <a big prime number> # e.g. p =3D 31
    hash =3D 1
    for each object you will use in equal do
       hash =3D 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>=
 wrote:
>
>> Easy way:
>
> I seem to have failed in communicating what I=92m after. =A0I wasn=92t af=
ter
> different ways of implementing #hash, I was after the golden standard
> of #hash implementations for value objects. =A0So, again, what=92s the
> standard way of implementing #hash for value objects in Ruby?
>
> If there isn=92t one, perhaps one should be agreed upon?
>
> One suggestion would be the XOR of the hash values of the object=92s
> class and its instance variables.
>
> Another is the XOR of the hash value of the object=92s class and the
> hash value of an Array containing its instance variables.
>