class Byebug::DAP::CapturedOutput

Captures an IO output stream. @api private

Attributes

captured[R]

The captured stream. Captured output can be read from this IO. @return [std:IO]

original[R]

The original stream, {std:IO#dup duplicated} from `io`. Writing to this IO will write to the original file. @return [std:IO]

Public Class Methods

new(io) click to toggle source

Capture `io`, {std:IO#dup duplicate} the original, open an {std:IO.pipe pipe} pair, and {std:IO#reopen reopen} `io` to redirect it to the pipe.

# File lib/byebug/dap/helpers/captured_output.rb, line 16
def initialize(io)
  @io = io
  @original = io.dup
  @captured, pw = IO.pipe

  io.reopen(pw)
  pw.close
end

Public Instance Methods

restore() click to toggle source

Restore `io` to the original file.

# File lib/byebug/dap/helpers/captured_output.rb, line 26
def restore
  @io.reopen(@original)
  @original.close
  @captured.close
  return nil
end