class HTTP::Response::StringBody

object.
A Body class that wraps a String, rather than a the client

def each

Iterate over the body, allowing it to be enumerable
def each
  yield @contents
end

def initialize(contents)

def initialize(contents)
  @contents = contents
  @streaming = nil
  @streaming_offset = 0
end

def inspect

Easier to interpret string inspect
def inspect
  "#<#{self.class}:#{object_id.to_s(16)}>"
end

def readpartial(size = @contents.length)

Returns:
  • (String, nil) - the next `size` octets part of the
def readpartial(size = @contents.length)
  stream!
  return nil if @streaming_offset >= @contents.length
  @contents[@streaming_offset, size].tap do |part|
    @streaming_offset += (part.length + 1)
  end
end

def stream!

Assert that the body is actively being streamed
def stream!
  fail StateError, "body has already been consumed" if @streaming == false
  @streaming = true
end

def to_s

Returns:
  • (String) - eagerly consume the entire body as a string
def to_s
  @contents
end