Skip to content

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

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.

See also #dump #each_char #downcase! #each_codepoint also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0