Maintenance Ruby 3.3 gets fixes, but no new features. 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 INT2FIX(0);
}
Truncates the buffer string to at most integer bytes. The stream must be opened for writing.