Skip to content

Instantly share code, notes, and snippets.

@calorie
Created October 4, 2013 14:11
Show Gist options
  • Save calorie/6826548 to your computer and use it in GitHub Desktop.
Save calorie/6826548 to your computer and use it in GitHub Desktop.
def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval("$#{stream} = #{stream.upcase}")
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment