End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
StringIO#truncate
strio.truncate(integer) → 0
ext/stringio/stringio.c
View on GitHub ↗
static VALUE
strio_truncate(VALUE self, VALUE len)
{
VALUE string = writable(self)->string;
long l = NUM2LONG(len);
long plen = RSTRING_LEN(string);
if (l < 0) {
error_inval("negative length");
}
rb_str_resize(string, l);
if (plen < l) {
MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
}
return len;
}
Truncates the buffer string to at most integer bytes. The stream must be opened for writing.