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
io.c
View on GitHub ↗
static VALUE
rb_io_set_lineno(VALUE io, VALUE lineno)
{
rb_io_t *fptr;
GetOpenFile(io, fptr);
rb_io_check_char_readable(fptr);
fptr->lineno = NUM2INT(lineno);
return lineno;
}
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