End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
IO#sync=
sync = boolean → boolean
io.c
View on GitHub ↗
static VALUE
rb_io_set_sync(VALUE io, VALUE sync)
{
rb_io_t *fptr;
io = GetWriteIO(io);
GetOpenFile(io, fptr);
if (RTEST(sync)) {
fptr->mode |= FMODE_SYNC;
}
else {
fptr->mode &= ~FMODE_SYNC;
}
return sync;
}
Sets the sync mode for the stream to the given value; returns the given value.
Values for the sync mode:
-
true: All output is immediately flushed to the underlying operating system and is not buffered internally. -
false: Output may be buffered internally.
Example;
Example
f = File.open('t.tmp', 'w') f.sync # => false f.sync = true f.sync # => true f.close
Related: IO#fsync.