[DOC] Tweaks for String#hash (#14253)

This commit is contained in:
Burdette Lamar 2025-08-21 08:37:19 -05:00 committed by GitHub
parent b6bf44ae0f
commit 027f4aa464
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

19
doc/string/hash.rdoc Normal file
View File

@ -0,0 +1,19 @@
Returns the integer hash value for +self+.
Two \String objects that have identical content and compatible encodings
also have the same hash value;
see Object#hash and {Encodings}[rdoc-ref:encodings.rdoc]:
s = 'foo'
h = s.hash # => -569050784
h == 'foo'.hash # => true
h == 'food'.hash # => false
h == 'FOO'.hash # => false
s0 = "äöü"
s1 = s0.encode(Encoding::ISO_8859_1)
s0.encoding # => #<Encoding:UTF-8>
s1.encoding # => #<Encoding:ISO-8859-1>
s0.hash == s1.hash # => false
Related: see {Querying}[rdoc-ref:String@Querying].

View File

@ -4133,10 +4133,8 @@ rb_str_hash_cmp(VALUE str1, VALUE str2)
* call-seq:
* hash -> integer
*
* Returns the integer hash value for +self+.
* The value is based on the length, content and encoding of +self+.
* :include: doc/string/hash.rdoc
*
* Related: Object#hash.
*/
static VALUE