capture

capture(stream)
Instance Public methods

Captures the given stream and returns it:

1
2
3
4
5
stream = capture(:stdout) { puts 'notice' }
stream # => "notice\n"
 
stream = capture(:stderr) { warn 'error' }
stream # => "error\n"

even for subprocesses:

1
2
3
4
5
stream = capture(:stdout) { system('echo notice') }
stream # => "notice\n"
 
stream = capture(:stderr) { system('echo error 1>&2') }
stream # => "error\n"

silence

doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.