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#rewind

rewind → 0

Repositions the stream to its beginning, setting both the position and the line number to zero; see Position and Line Number:

Example
f = File.open('t.txt')
f.tell     # => 0
f.lineno   # => 0
f.readline # => "This is line one.\n"
f.tell     # => 19
f.lineno   # => 1
f.rewind   # => 0
f.tell     # => 0
f.lineno   # => 0

Note that this method 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.0