Class: RackConsole::OutputCapture

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_console/output_capture.rb

Instance Method Summary collapse

Constructor Details

#initializeOutputCapture

Returns a new instance of OutputCapture.



5
6
7
8
9
# File 'lib/rack_console/output_capture.rb', line 5

def initialize
  @old = $stdout
  @io = ::StringIO.new
  @main_thread = ::Thread.current
end

Instance Method Details

#captureObject



15
16
17
18
19
20
# File 'lib/rack_console/output_capture.rb', line 15

def capture
  $stdout = self
  yield
ensure
  $stdout = @old
end

#outputObject



22
23
24
25
# File 'lib/rack_console/output_capture.rb', line 22

def output
  @io.rewind
  @io.read
end

#write(value) ⇒ Object



11
12
13
# File 'lib/rack_console/output_capture.rb', line 11

def write(value)
  io.write(value)
end