Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#oct

oct → integer

Interprets the leading substring of self as a string of octal digits (with an optional sign) and returns the corresponding number; returns zero if there is no such leading substring:

Example
'123'.oct             # => 83
'-377'.oct            # => -255
'0377non-numeric'.oct # => 255
'non-numeric'.oct     # => 0

If self starts with 0, radix indicators are honored; see Kernel#Integer.

Related: String#hex.

See also #next! #ord #next #partition also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0