End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO#pos=
ios.pos = integer → integer
io.c
View on GitHub ↗
static VALUE
rb_io_set_pos(VALUE io, VALUE offset)
{
rb_io_t *fptr;
off_t pos;
pos = NUM2OFFT(offset);
GetOpenFile(io, fptr);
pos = io_seek(fptr, pos, SEEK_SET);
if (pos < 0 && errno) rb_sys_fail_path(fptr->pathv);
return OFFT2NUM(pos);
}
Seeks to the given position (in bytes) in ios. It is not guaranteed that seeking to the right position when ios is textmode.
Example
f = File.new("testfile") f.pos = 17 f.gets #=> "This is line two\n"