VOOZH about

URL: https://apidock.com/ruby/String/oct

⇱ String#oct - APIdock


method

oct

ruby latest stable - Class: String
oct()
public

Treats leading characters of str as a string of octal digits (with an optional sign) and returns the corresponding number. Returns 0 if the conversion fails.

"123".oct #=> 83
"-377".oct #=> -255
"bad".oct #=> 0
"0377bad".oct #=> 255

If starts with 0, radix indicators are honored. See Kernel#Integer.

static VALUE
rb_str_oct(VALUE str)
{
 return rb_str_to_inum(str, -8, FALSE);
}

Related methods