Class: WrapIO::Capture

Inherits:
Object
  • Object
show all
Defined in:
lib/wrapio/capture.rb

Overview

A small class built to capture the output from STDOUT.

Class Method Summary collapse

Class Method Details

.output { ... } ⇒ Object

Captures the output of $stdout. Temporarily swaps $stdout with an instance of the StringIO class.

Yields:

  • the block of code from which to capture output



14
15
16
17
18
19
20
21
22
23
# File 'lib/wrapio/capture.rb', line 14

def self.output
	begin
		$stdout = captor = StringIO.new
		yield
	ensure
		$stdout = STDOUT
	end
	WrapIO.log(captor.string, :output) if WrapIO.debug
	captor.string
end