Skip to content
class method

IO::Buffer.string

(::int) { (::IO::Buffer) -> void } -> ::String
IO::Buffer.string(length) {|io_buffer| ... read/write io_buffer ...} → string

Creates a new string of the given length and yields a zero-copy IO::Buffer instance to the block which uses the string as a source. The block is expected to write to the buffer and the string will be returned.

Example
IO::Buffer.string(4) do |buffer|
  buffer.set_string("Ruby")
end
# => "Ruby"
See also .size_of #& .new #<=> also in 4.1 · 3.4 · 3.3