Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO#getbyte

() -> ::Integer?
getbyte → integer or nil

Reads and returns the next byte (in range 0..255) from the stream; returns nil if already at end-of-stream. See Byte IO.

Example
f = File.open('t.txt')
f.getbyte # => 70
f.close
File.read('t.ja') # => "こんにちは"
f = File.open('t.ja')
f.getbyte # => 227
f.close

Related: IO#readbyte (may raise EOFError).

See also #fsync #getc #flush #getch also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0