Class: Utils
- Inherits:
-
Object
- Object
- Utils
- Defined in:
- lib/puppet-check/utils.rb
Overview
utility methods totally not edited from StackOverflow
Class Method Summary collapse
-
.capture_stderr ⇒ Object
captures stderr from a block: err = capture_stderr { code }.
-
.capture_stdout ⇒ Object
captures stdout from a block: out = capture_stdout { code }.
Class Method Details
.capture_stderr ⇒ Object
captures stderr from a block: err = capture_stderr { code }
17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet-check/utils.rb', line 17 def self.capture_stderr Thread.current[:old_stderr] = $stderr $stderr = StringIO.new yield $stderr.string ensure $stderr = Thread.current[:old_stderr] if Thread.current[:old_stderr] Thread.current[:old_stderr] = nil end |
.capture_stdout ⇒ Object
captures stdout from a block: out = capture_stdout { code }
6 7 8 9 10 11 12 13 14 |
# File 'lib/puppet-check/utils.rb', line 6 def self.capture_stdout Thread.current[:old_stdout] = $stdout $stdout = StringIO.new yield $stdout.string ensure $stdout = Thread.current[:old_stdout] if Thread.current[:old_stdout] Thread.current[:old_stdout] = nil end |