Skip to content

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

instance method

String#bytes

str.bytes → an_array

Returns an array of bytes in str. This is a shorthand for str.each_byte.to_a.

If a block is given, which is a deprecated form, works the same as each_byte.

See also #b #bytesize #ascii_only? #byteslice also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0