Top Level Namespace
Instance Method Summary collapse
-
#silent(*what) ⇒ Object
Silently execute a block.
Instance Method Details
#silent(*what) ⇒ Object
Silently execute a block. Arguments should be :stdout and/or :stderr, and a block should be given.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/silent.rb', line 5 def silent(*what) return unless block_given? _stdout, $stdout = $stdout, StringIO.new if what.include?(:stdout) _stderr, $stderr = $stderr, StringIO.new if what.include?(:stderr) res = yield $stdout = _stdout if what.include?(:stdout) $stderr = _stderr if what.include?(:stderr) res end |