Bug #6068

String::Hash documentation clarification

Added by peck (Daniel Peck) over 8 years ago. Updated over 8 years ago.

Target version:
ruby -v:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]


modified documentation for String::hash to clarify that results are not conistent across sessions and advice for if that behavior is desired


Updated by marcandre (Marc-Andre Lafortune) over 8 years ago

I'm not sure that all implementations have to return hash codes that differ from one run to the other. I would also modify Object#hash, as all hashes in CRuby are random seeded, not just String. I'd recommend adding the following line to Object#hash:

No other assumption can be made on hash values; in particular they may vary between sessions or implementations.


Updated by drbrain (Eric Hodel) over 8 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34769.
Daniel, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

  • object.c (rb_obj_hash): Added note that the hash value is not deterministic on Marc-Andre's suggestion. Expanded description of the purpose of the hash method. [Bug #6068]

Updated by drbrain (Eric Hodel) over 8 years ago

Daniel, I couldn't use your patch as it was not line-wrapped to 80 columns and was too-specific to String. As Marc-Andre pointed out, the randomization behavior applies to Fixnum, Hash, String, Symbol, Array, etc., so I applied a patch based on his suggestion.

Also available in: Atom PDF