instance method
String#each_byte
() -> ::Enumerator[::Integer, self]
() { (::Integer byte) -> void } -> self
each_byte {|byte| ... } → self
each_byte → enumerator
string.c
View on GitHub ↗
static VALUE
rb_str_each_byte(VALUE str)
{
RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_byte_size);
return rb_str_enumerate_bytes(str, 0);
}
With a block given, calls the block with each successive byte from self; returns self:
Example
a = [] 'hello'.each_byte {|byte| a.push(byte) } # Five 1-byte characters. a # => [104, 101, 108, 108, 111] a = [] 'тест'.each_byte {|byte| a.push(byte) } # Four 2-byte characters. a # => [209, 130, 208, 181, 209, 129, 209, 130] a = [] 'こんにちは'.each_byte {|byte| a.push(byte) } # Five 3-byte characters. a # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
With no block given, returns an enumerator.
Related: see Iterating.