Skip to content

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

instance method

IO#each_byte

ios.each_byte {|byte| block } → ios
ios.each_byte → an_enumerator

Calls the given block once for each byte (0..255) in ios, passing the byte as an argument. The stream must be opened for reading or an IOError will be raised.

If no block is given, an enumerator is returned instead.

Example
f = File.new("testfile")
checksum = 0
f.each_byte {|x| checksum ^= x }   #=> #<File:testfile>
checksum                           #=> 12
See also #each #each_char #cursor_up #each_codepoint also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0