Obj.hash now == obj.hash after?

Hi gurus and nubys,

I just noticed that if I create a dummy class and create instances
from it, I have obj.hash==obj.id

I know that id (soon to be deprecated, I know :wink: guarantees that two
active objects wont get the same id in the same time, but I supposed
that hash would give a unique value for any object in any time.

If I marshal an object, restart ruby and reload it, will I get the
same hash? what about the id ? why they look the same thing ?

Hi,

I know that id (soon to be deprecated, I know :wink: guarantees that two
active objects wont get the same id in the same time, but I supposed
that hash would give a unique value for any object in any time.

No, hash values are used for hashing values by Hash. It does not need
full uniqueness. Conflicts just slows down a Hash.

If I marshal an object, restart ruby and reload it, will I get the
same hash? what about the id ? why they look the same thing ?

No. Marshal makes copies. Hash values may not be same for copied
objects, even for cloned objects.

						matz.
···

In message “obj.hash now == obj.hash after?” on 03/05/15, gabriele renzi surrender_it@rc1.vip.lng.yahoo.com writes:

“gabriele renzi” surrender_it@remove.yahoo.it schrieb im Newsbeitrag
news:3oh5cvsnsiu6pjdvjjhaa5v967h8uho88r@4ax.com

Hi gurus and nubys,

I just noticed that if I create a dummy class and create instances
from it, I have obj.hash==obj.id

I know that id (soon to be deprecated, I know :wink: guarantees that two
active objects wont get the same id in the same time, but I supposed
that hash would give a unique value for any object in any time.

If I marshal an object, restart ruby and reload it, will I get the
same hash? what about the id ? why they look the same thing ?

That’s the default implementation. If you create a class, where several
non identical instances should be treated es eqivalent (like strings) you
should override some methods appropriately. I set up a wiki page for
this:

Regards

robert

thanks Robert & Matz for the explanations

···

il Wed, 14 May 2003 22:55:25 GMT, gabriele renzi surrender_it@remove.yahoo.it ha scritto::