Module: Flux::Util::Output

Defined in:
lib/flux/util/output.rb

Instance Method Summary collapse

Instance Method Details

#capture(channel = :stdout) { ... } ⇒ Object Also known as: silence

Capture standard IO channel.

Yields:

  • the block that encloses the channel capture

Returns:

  • everything that was written to the given channel



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/flux/util/output.rb', line 9

def capture(channel = :stdout)
  io     = StringIO.new
  old_io = eval("$#{channel}")

  eval("$#{channel} = io")

  yield

  io.string
ensure
  eval("$#{channel} = old_io")
end