Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
IO::Buffer::Storage#initialize_copy
dup → io_buffer
clone → io_buffer
io_buffer.c
View on GitHub ↗
static VALUE
rb_io_buffer_initialize_copy(VALUE self, VALUE source)
{
if (self == source) return self;
rb_check_frozen(self);
return rb_io_buffer_locked_for_reading(source, io_buffer_initialize_copy_from, self);
}
Make an internal copy of the source buffer. Updates to the copy will not affect the source buffer.
Example
source = IO::Buffer.for("Hello World") # => # #<IO::Buffer 0x00007fd598466830+11 EXTERNAL READONLY SLICE> # 0x00000000 48 65 6c 6c 6f 20 57 6f 72 6c 64 Hello World buffer = source.dup # => # #<IO::Buffer 0x0000558cbec03320+11 INTERNAL> # 0x00000000 48 65 6c 6c 6f 20 57 6f 72 6c 64 Hello World