Projects

Output Catcher for Ruby and Rails

By matthias

OutputCatcher is available as a gem and as a Rails plugin. It provides a way to capture the standard out($stdout) or standard error($stderr) of your code without pain and suppresses the output of the ‘err’ or ‘out’ stream.

$ gem install mhennemeyer-output_catcher —source=http://gems.github.com

For rails:

$ ruby script/plugin install git://github.com/mhennemeyer/output_catcher.git

OutputCatcher knows only two methods: .catch_err and .catch_out

To capture the stderr of your code:

1
2
3
4
5
 
 err = OutputCatcher.catch_err do
    $stderr << "error error"
  end
  err #=> "error error"
To capture the stdout of your code:
1
2
3
4
5
6
 
  out = OutputCatcher.catch_out do
    puts "Hello Hello"
  end
  out #=> "Hello Hello"
  

Released under the MIT license.

 
Projects