instance method
String#bytes
() -> ::Array[::Integer]
() { (::Integer byte) -> void } -> self
bytes → array_of_bytes
string.c
View on GitHub ↗
static VALUE
rb_str_bytes(VALUE str)
{
VALUE ary = WANTARRAY("bytes", RSTRING_LEN(str));
return rb_str_enumerate_bytes(str, ary);
}
Returns an array of the bytes in self:
Example
'hello'.bytes # => [104, 101, 108, 108, 111] 'Привет'.bytes # => [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130] 'こんにちは'.bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
Related: see Converting to Non-String.