Module: Capture
- Defined in:
- lib/capture-output.rb
Class Method Summary collapse
Class Method Details
.output(out = STDOUT) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/capture-output.rb', line 2 def self.output(out = STDOUT) r, w = IO.pipe old_out = out.clone out.reopen(w) data = '' t = Thread.new do data << r.read end begin yield ensure w.close out.reopen(old_out) end t.join data end |
.stderr(&block) ⇒ Object
26 27 28 |
# File 'lib/capture-output.rb', line 26 def self.stderr(&block) output(STDERR, &block) end |
.stdout(&block) ⇒ Object
22 23 24 |
# File 'lib/capture-output.rb', line 22 def self.stdout(&block) output(STDOUT, &block) end |