instance method
StringIO#truncate
(::Integer) -> 0
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;
if (l < 0) {
error_inval("negative length");
}
if (NIL_P(string)) return 0;
plen = RSTRING_LEN(string);
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.