@@ -10744,20 +10744,79 @@ rb_str_hex(VALUE str)
1074410744 * call-seq:
1074510745 * oct -> integer
1074610746 *
10747- * Interprets the leading substring of +self+ as a string of octal digits
10748- * (with an optional sign) and returns the corresponding number;
10749- * returns zero if there is no such leading substring:
10747+ * Interprets the leading substring of +self+ as octal, binary, decimal, or hexadecimal, possibly signed;
10748+ * returns their value as an integer.
1075010749 *
10751- * '123'.oct # => 83
10752- * '-377'.oct # => -255
10753- * '0377non-numeric'.oct # => 255
10754- * 'non-numeric'.oct # => 0
10750+ * In brief:
1075510751 *
10756- * If +self+ starts with <tt>0</tt>, radix indicators are honored;
10757- * see Kernel#Integer.
10752+ * # Interpreted as octal.
10753+ * '777'.oct # => 511
10754+ * '777x'.oct # => 511
10755+ * '0777'.oct # => 511
10756+ * '0o777'.oct # => 511
10757+ * '-777'.oct # => -511
10758+ * # Not interpreted as octal.
10759+ * '0b111'.oct # => 7 # Interpreted as binary.
10760+ * '0d999'.oct # => 999 # Interpreted as decimal.
10761+ * '0xfff'.oct # => 4095 # Interpreted as hexadecimal.
1075810762 *
10759- * Related: String#hex.
10763+ * The leading substring is interpreted as octal when it begins with:
1076010764 *
10765+ * - One or more character representing octal digits
10766+ * (each in the range <tt>'0'..'7'</tt>);
10767+ * the string to be interpreted ends at the first character that does not represent an octal digit:
10768+ *
10769+ * '7'.oct @ => 7
10770+ * '11'.oct # => 9
10771+ * '777'.oct # => 511
10772+ * '0777'.oct # => 511
10773+ * '7778'.oct # => 511
10774+ * '777x'.oct # => 511
10775+ *
10776+ * - <tt>'0o'</tt>, followed by one or more octal digits:
10777+ *
10778+ * '0o777'.oct # => 511
10779+ * '0o7778'.oct # => 511
10780+ *
10781+ * The leading substring is _not_ interpreted as octal when it begins with:
10782+ *
10783+ * - <tt>'0b'</tt>, followed by one or more characters representing binary digits
10784+ * (each in the range <tt>'0'..'1'</tt>);
10785+ * the string to be interpreted ends at the first character that does not represent a binary digit.
10786+ * the string is interpreted as binary digits (base 2):
10787+ *
10788+ * '0b111'.oct # => 7
10789+ * '0b1112'.oct # => 7
10790+ *
10791+ * - <tt>'0d'</tt>, followed by one or more characters representing decimal digits
10792+ * (each in the range <tt>'0'..'9'</tt>);
10793+ * the string to be interpreted ends at the first character that does not represent a decimal digit.
10794+ * the string is interpreted as decimal digits (base 10):
10795+ *
10796+ * '0d999'.oct # => 999
10797+ * '0d999x'.oct # => 999
10798+ *
10799+ * - <tt>'0x'</tt>, followed by one or more characters representing hexadecimal digits
10800+ * (each in one of the ranges <tt>'0'..'9'</tt>, <tt>'a'..'f'</tt>, or <tt>'A'..'F'</tt>);
10801+ * the string to be interpreted ends at the first character that does not represent a hexadecimal digit.
10802+ * the string is interpreted as hexadecimal digits (base 16):
10803+ *
10804+ * '0xfff'.oct # => 4095
10805+ * '0xfffg'.oct # => 4095
10806+ *
10807+ * Any of the above may prefixed with <tt>'-'</tt>, which negates the interpreted value:
10808+ *
10809+ * '-777'.oct # => -511
10810+ * '-0777'.oct # => -511
10811+ * '-0b111'.oct # => -7
10812+ * '-0xfff'.oct # => -4095
10813+ *
10814+ * For any substring not described above, returns zero:
10815+ *
10816+ * 'foo'.oct # => 0
10817+ * ''.oct # => 0
10818+ *
10819+ * Related: see {Converting to Non-String}[rdoc-ref:String@Converting+to+Non--5CString].
1076110820 */
1076210821
1076310822static VALUE
0 commit comments