Skip to content

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

instance method

String#each_byte

str.each_byte {|integer| block } → str
str.each_byte → an_enumerator

Passes each byte in str to the given block, or returns an enumerator if no block is given.

Example
"hello".each_byte {|c| print c, ' ' }

produces:

104 101 108 108 111
See also #dump #each_char #downcase! #each_codepoint also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1