Class: Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-check/utils.rb

Overview

utility methods totally not edited from StackOverflow

Class Method Summary collapse

Class Method Details

.capture_stderrObject

captures stderr from a block: err = capture_stderr { code }



14
15
16
17
18
19
20
21
# File 'lib/puppet-check/utils.rb', line 14

def self.capture_stderr
  old_stderr = $stderr
  $stderr = StringIO.new
  yield
  $stderr.string
ensure
  $stderr = old_stderr
end

.capture_stdoutObject

captures stdout from a block: out = capture_stdout { code }



4
5
6
7
8
9
10
11
# File 'lib/puppet-check/utils.rb', line 4

def self.capture_stdout
  old_stdout = $stdout
  $stdout = StringIO.new
  yield
  $stdout.string
ensure
  $stdout = old_stdout
end