Module: Kernel

Defined in:
lib/toaster/toaster_app_service.rb

Overview

capture stdout using thread-local variable require ‘stringio’

Instance Method Summary collapse

Instance Method Details

#capture_stdout(&block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/toaster/toaster_app_service.rb', line 52

def capture_stdout(&block)
  out = StringIO.new
  Thread.start do
    begin
      Thread.current[:stdout] = out
      block.call
    ensure
      Thread.current[:stdout] = STDOUT
    end
  end.join
  return out.string
end