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 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 ?
I know that id (soon to be deprecated, I know 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.
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 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: