class Object
Public Instance Methods
silent(*what) { || ... }
click to toggle source
Silently execute a block. @param what [Symbol] output to silent. This must be either :stdout
or
+:stderr:+. More than can be given.
@yield [] @return block’s returned value
# File lib/silent.rb, line 7 def silent(*what) return unless block_given? begin _stdout, $stdout = $stdout, StringIO.new if what.include?(:stdout) _stderr, $stderr = $stderr, StringIO.new if what.include?(:stderr) yield ensure $stdout = _stdout if what.include?(:stdout) $stderr = _stderr if what.include?(:stderr) end end