Method: IO#pos=

Defined in:
io.c

#pos=(new_position) ⇒ Object

Seeks to the given new_position (in bytes); see Position:

f = File.open('t.txt')
f.tell     # => 0
f.pos = 20 # => 20
f.tell     # => 20
f.close

Related: IO#seek, IO#tell.

[View source]

2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
# File 'io.c', line 2551

static VALUE
rb_io_set_pos(VALUE io, VALUE offset)
{
    rb_io_t *fptr;
    rb_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);
}