Method: Utils::IRB::Shell#capture_output
- Defined in:
- lib/utils/irb.rb
#capture_output(with_stderr = false) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/utils/irb.rb', line 266 def capture_output(with_stderr = false) return "missing block" unless block_given? require 'tempfile' begin old_stdout, $stdout = $stdout, Tempfile.new('irb') if with_stderr old_stderr, $stderr = $stderr, $stdout end yield ensure $stdout, temp = old_stdout, $stdout with_stderr and $stderr = old_stderr end temp.rewind temp.read end |