instance method
StringIO#string=
(::String str) -> ::String
string = other_string → other_string
ext/stringio/stringio.c
View on GitHub ↗
static VALUE
strio_set_string(VALUE self, VALUE string)
{
struct StringIO *ptr = StringIO(self);
rb_io_taint_check(self);
ptr->flags &= ~FMODE_READWRITE;
StringValue(string);
ptr->flags = readonly_string_p(string) ? FMODE_READABLE : FMODE_READWRITE;
ptr->pos = 0;
ptr->lineno = 0;
RB_OBJ_WRITE(self, &ptr->string, string);
return string;
}
Replaces the stored string with other_string, and sets the position to zero; returns other_string:
Example
StringIO.open('foo') do |strio| p strio.string strio.string = 'bar' p strio.string end
Output:
Example
"foo" "bar"
Related: StringIO#string (returns the stored string).