Is the value returned by ruby's #hash the same across interpreter instances?
Is the value returned by ruby's #hash the same across interpreter instances?
For example, if I do "some string".hash
, will I always get the same number even if run in different instances of the interpreter? If so, is this also true for all the开发者_JAVA技巧 builtin types (e.g. Hash
, FixNum
, etc).
Not the same in different instances, at least with Ruby 1.9.1.
This link gives some further info...
It seems that they changed hash algorithm in 1.9 to a random seed-based one...
If you want to do something that you know will be the same across versions and objects try md5 or sha1.
require 'digest/md5'
Digest::MD5.hexdigest('some string')
精彩评论