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#lineno=

ios.lineno = integer → integer

Manually sets the current line number to the given value. $. is updated only on the next read.

Example
f = File.new("testfile")
f.gets                     #=> "This is line one\n"
$.                         #=> 1
f.lineno = 1000
f.lineno                   #=> 1000
$.                         #=> 1         # lineno of last read
f.gets                     #=> "This is line two\n"
$.                         #=> 1001      # lineno of last read
See also #lineno #noecho #isatty #nonblock also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1