Skip to content

Instantly share code, notes, and snippets.

@Bill
Created April 17, 2009 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bill/96776 to your computer and use it in GitHub Desktop.
Save Bill/96776 to your computer and use it in GitHub Desktop.
# capture a yaml dump of an object like this:
# capture { y request }
module Kernel
def capture # pass a block to capture
old_stdout = $stdout
out = StringIO.new
$stdout = out
begin
yield
ensure
$stdout = old_stdout
end
out.string
end
module_function :capture
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment