Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
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);
}
Calls the given block with each successive byte from self; returns self:
Example
'hello'.each_byte {|byte| print byte, ' ' } print "\n" 'тест'.each_byte {|byte| print byte, ' ' } print "\n" 'こんにちは'.each_byte {|byte| print byte, ' ' } print "\n"
Output:
104 101 108 108 111 209 130 208 181 209 129 209 130 227 129 147 227 130 147 227 129 171 227 129 161 227 129 175
Returns an enumerator if no block is given.