End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
StringScanner#pointer=
pointer=(p1)
ext/strscan/strscan.c
View on GitHub ↗
static VALUE
strscan_set_pos(VALUE self, VALUE v)
{
struct strscanner *p;
long i;
GET_SCANNER(self, p);
i = NUM2INT(v);
if (i < 0) i += S_LEN(p);
if (i < 0) rb_raise(rb_eRangeError, "index out of range");
if (i > S_LEN(p)) rb_raise(rb_eRangeError, "index out of range");
p->curr = i;
return LONG2NUM(i);
}
Alias of #pos=
Sets the byte position of the scan pointer.
Example
s = StringScanner.new('test string') s.pos = 7 # -> 7 s.rest # -> "ring"