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

IO#rewind

ios.rewind → 0

Positions ios to the beginning of input, resetting lineno to zero.

Example
f = File.new("testfile")
f.readline   #=> "This is line one\n"
f.rewind     #=> 0
f.lineno     #=> 0
f.readline   #=> "This is line one\n"

Note that it cannot be used with streams such as pipes, ttys, and sockets.

See also #reopen #scroll_backward #ready? #scroll_forward also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1