method

capture

Importance_1
v4.2.9 - Show latest stable - 0 notes - Class: Kernel
capture(stream) public

Captures the given stream and returns it:

stream = capture(:stdout) { puts 'notice' }
stream # => "notice\n"

stream = capture(:stderr) { warn 'error' }
stream # => "error\n"

even for subprocesses:

stream = capture(:stdout) { system('echo notice') }
stream # => "notice\n"

stream = capture(:stderr) { system('echo error 1>&2') }
stream # => "error\n"
Show source
Register or log in to add new notes.