From 027f4aa464f92cb4884561ef277db20f8eff5732 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Thu, 21 Aug 2025 08:37:19 -0500 Subject: [PATCH] [DOC] Tweaks for String#hash (#14253) --- doc/string/hash.rdoc | 19 +++++++++++++++++++ string.c | 4 +--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 doc/string/hash.rdoc diff --git a/doc/string/hash.rdoc b/doc/string/hash.rdoc new file mode 100644 index 0000000000..fe94770ed9 --- /dev/null +++ b/doc/string/hash.rdoc @@ -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 # => # + s1.encoding # => # + s0.hash == s1.hash # => false + +Related: see {Querying}[rdoc-ref:String@Querying]. diff --git a/string.c b/string.c index d9d8678c71..0329d2845a 100644 --- a/string.c +++ b/string.c @@ -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