class Bytes::Builder

A mutable buffer of bytes, for building Bytes piece by piece.

It is not Shareable. Unlike the other builders', #to_bytes copies and leaves the contents in place, as #snapshot does.

b = Bytes::Builder.new
b << 0x68 << b"\xc3\xa9" << "llo"
b.size                   # => 6
b.to_bytes               # => b"h\xc3\xa9llo"
b.size                   # => 6

<prelude>:1663

Class methods

def self.new -> Bytes::Builder

An empty builder.

<prelude>:1667

Methods

def <<(byte: Int) -> Self

Appends byte and returns the builder. Raises RangeError for a value outside 0..255.

<prelude>:1670

def <<(bytes: Bytes) -> Self

Appends bytes and returns the builder.

<prelude>:1672

def <<(text: String) -> Self

Appends the UTF-8 bytes of text and returns the builder.

<prelude>:1674

def push(byte: Int) -> Self

Appends byte and returns the builder, as #<<. Raises RangeError for a value outside 0..255.

<prelude>:1677

def size -> Int

The number of bytes held.

<prelude>:1679

def empty? -> Bool

Whether the builder holds no byte.

<prelude>:1681

def clear -> Self

Removes every byte and returns the builder.

<prelude>:1683

def to_bytes -> Bytes

The bytes held, as Bytes. The builder keeps them: the result is a copy.

<prelude>:1685

def snapshot -> Bytes

A copy of the bytes held, as Bytes; the builder keeps them.

<prelude>:1687

def to_s -> String

The literal form of the bytes held, as Bytes#to_s.

<prelude>:1689

def inspect -> String

The literal form of the bytes held, as Bytes#inspect.

<prelude>:1691