Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active December 14, 2015 15:08
Show Gist options
  • Save havenwood/5105232 to your computer and use it in GitHub Desktop.
Save havenwood/5105232 to your computer and use it in GitHub Desktop.
Send puts output to OS X clipboard inside a block
def clipboard
yield
pbcopy = IO.popen 'pbcopy', 'w'
$stdout = pbcopy
yield
ensure
pbcopy.close
$stdout = STDOUT
end
clipboard do
print 'ready to paste!'
end
# paste me=> nil # also copied to clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment