Module: NoStdout::InstanceMethods
- Defined in:
- lib/support/no_stdout.rb
Overview
:nodoc:all
Instance Method Summary collapse
-
#last_stderr ⇒ Object
returns the contents of STDERR from the previous usage of no_stderr, or nil.
-
#last_stdout ⇒ Object
returns the contents of STDOUT from the previous usage of no_stdout, or nil.
-
#no_stderr(to = StringIO.new('','r+'), &block) ⇒ Object
Suppresses or redirects STDERR inside the given block.
-
#no_stdout(to = StringIO.new('','r+'), &block) ⇒ Object
Suppresses or redirects STDOUT inside the given block.
Instance Method Details
#last_stderr ⇒ Object
returns the contents of STDERR from the previous usage of no_stderr, or nil
43 44 45 46 47 |
# File 'lib/support/no_stdout.rb', line 43 def last_stderr return nil unless @alt_stderr @alt_stderr.rewind @alt_stderr.read end |
#last_stdout ⇒ Object
returns the contents of STDOUT from the previous usage of no_stdout, or nil
22 23 24 25 26 |
# File 'lib/support/no_stdout.rb', line 22 def last_stdout return nil unless @alt_stdout @alt_stdout.rewind @alt_stdout.read end |
#no_stderr(to = StringIO.new('','r+'), &block) ⇒ Object
Suppresses or redirects STDERR inside the given block. supply an IO of your own to capture STDERR, otherwise it’s put in a new StringIO object.
33 34 35 36 37 38 39 |
# File 'lib/support/no_stdout.rb', line 33 def no_stderr ( to = StringIO.new('','r+'), &block ) orig_stderr = $stderr $stderr = @alt_stderr = to result = yield $stderr = orig_stderr result end |
#no_stdout(to = StringIO.new('','r+'), &block) ⇒ Object
Suppresses or redirects STDOUT inside the given block. supply an IO of your own to capture STDOUT, otherwise it’s put in a new StringIO object.
12 13 14 15 16 17 18 |
# File 'lib/support/no_stdout.rb', line 12 def no_stdout ( to = StringIO.new('','r+'), &block ) orig_stdout = $stdout $stdout = @alt_stdout = to result = yield $stdout = orig_stdout result end |