Skip to content

Commit d96991c

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Tweaks for String#hex
1 parent 4d0836d commit d96991c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

string.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10681,18 +10681,21 @@ rb_str_scan(VALUE str, VALUE pat)
1068110681
* call-seq:
1068210682
* hex -> integer
1068310683
*
10684-
* Interprets the leading substring of +self+ as a string of hexadecimal digits
10685-
* (with an optional sign and an optional <code>0x</code>) and returns the
10686-
* corresponding number;
10687-
* returns zero if there is no such leading substring:
10684+
* Interprets the leading substring of +self+ as hexadecimal;
10685+
* returns its integer value:
10686+
*
10687+
* '0xFFFF'.hex # => 65535
10688+
* 'FFzzzFF'.hex # => 255 # Hex ends at first non-hex character, 'z'.
10689+
* 'ffzzzFF'.hex # => 255 # Case does not matter.
10690+
* '-FFzzzFF'.hex # => -255 # May have leading '-'.
10691+
* '0xFFzzzFF'.hex # => 255 # May have leading '0x'.
10692+
* '-0xFFzzzFF'.hex # => -255 # May have leading '-0x'.
1068810693
*
10689-
* '0x0a'.hex # => 10
10690-
* '-1234'.hex # => -4660
10691-
* '0'.hex # => 0
10692-
* 'non-numeric'.hex # => 0
10694+
* Returns zero if there is no such leading substring:
1069310695
*
10694-
* Related: String#oct.
10696+
* 'zzz'.hex # => 0
1069510697
*
10698+
* Related: See {Converting to Non-String}[rdoc-ref:String@Converting+to+Non--5CString].
1069610699
*/
1069710700

1069810701
static VALUE

0 commit comments

Comments
 (0)