Different hashes for the same object values ​​in ruby

I have a problem with the hash method from ruby: http://apidock.com/ruby/v1_8_7_330/Hash/hash

I use this to compare two different objects with the same content in order to find a collision between the database objects and the new elements with the same attributes.

It worked, apparently, for a long time (more than one year), but it suddenly stopped working on my development computer.

If I try this in the rails console:

a = {:a => 'a', :b=>'b'}
b = {:a => 'a', :b=>'b'}
a.hash
b.hash

I get the same value for a.hash and b.hash ( -3820017043059270405) in the same console. The problem is that if I switch to another console, it returns a different value from the first console ( -1865824882785682267).

Shouldn't the same hash ever be returned ?

Thanks in advance.

: - 1.8.7.

+5
2

, !

Ruby (, jRuby, Rubinius, MRI 1.8.x, MRI 1.9.x ..) . , (, Hash) uniq . , MRI : http://rxr.whitequark.org/mri/source/gc.c?v=1.8.7-p370#2111

, , .

ruby-doc apidock Ruby: http://ruby-doc.org/core-2.0/Object.html#method-i-hash

ruby. ruby, .

, !

+5

: http://ruby-doc.org/core-2.0/Object.html#method-i-hash

. ruby invocations .

Ruby 2.0, , - .. , Ruby, .eql? -, Ruby.

Hash.hash, , -, , -, , , .

0

All Articles