summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorBurdetteLamar <burdettelamar@yahoo.com>2025-08-16 11:18:33 -0500
committerPeter Zhu <peter@peterzhu.ca>2025-08-16 17:04:35 -0400
commitd96991cc37b9c73372a8d0a61c5d83a2ce5b0cbe (patch)
tree3dcb7c007b335e2b9969d18c916aa0af3d628a63 /string.c
parent4d0836d928839ff13580f5e5b74a40b3914d9f59 (diff)
[DOC] Tweaks for String#hex
Diffstat (limited to 'string.c')
-rw-r--r--string.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/string.c b/string.c
index 96a9f96bd3..73b5bf83fc 100644
--- a/string.c
+++ b/string.c
@@ -10681,18 +10681,21 @@ rb_str_scan(VALUE str, VALUE pat)
* call-seq:
* hex -> integer
*
- * Interprets the leading substring of +self+ as a string of hexadecimal digits
- * (with an optional sign and an optional <code>0x</code>) and returns the
- * corresponding number;
- * returns zero if there is no such leading substring:
+ * Interprets the leading substring of +self+ as hexadecimal;
+ * returns its integer value:
+ *
+ * '0xFFFF'.hex # => 65535
+ * 'FFzzzFF'.hex # => 255 # Hex ends at first non-hex character, 'z'.
+ * 'ffzzzFF'.hex # => 255 # Case does not matter.
+ * '-FFzzzFF'.hex # => -255 # May have leading '-'.
+ * '0xFFzzzFF'.hex # => 255 # May have leading '0x'.
+ * '-0xFFzzzFF'.hex # => -255 # May have leading '-0x'.
*
- * '0x0a'.hex # => 10
- * '-1234'.hex # => -4660
- * '0'.hex # => 0
- * 'non-numeric'.hex # => 0
+ * Returns zero if there is no such leading substring:
*
- * Related: String#oct.
+ * 'zzz'.hex # => 0
*
+ * Related: See {Converting to Non-String}[rdoc-ref:String@Converting+to+Non--5CString].
*/
static VALUE