Skip to content
instance method

IO::Buffer#set_string

(*untyped) -> untyped
set_string(string, [offset, [length, [source_offset]]]) → size

Efficiently copy from a source String into the buffer, at offset using memmove.

Example
buf = IO::Buffer.new(8)
# =>
# #<IO::Buffer 0x0000557412714a20+8 INTERNAL>
# 0x00000000  00 00 00 00 00 00 00 00                         ........

# set buffer starting from offset 1, take 2 bytes starting from string's
# second
buf.set_string('test', 1, 2, 1)
# => 2
buf
# =>
# #<IO::Buffer 0x0000557412714a20+8 INTERNAL>
# 0x00000000  00 65 73 00 00 00 00 00                         .es.....

See also copy for examples of how buffer writing might be used for changing associated strings and files.

See also #resize #set_value #readonly? #set_values also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1