Created
June 5, 2009 13:25
-
-
Save kbrock/124279 to your computer and use it in GitHub Desktop.
copy an irb command to clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
copy { | |
puts "puts 'hello world'" | |
} | |
#command V | |
ep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# thanks: | |
# http://stefankst.net/2007/06/05/capture-standard-output-in-ruby/ | |
# http://judofyr.net/posts/copy-paste-irb.html | |
# stick in .irbrc | |
def copy(str=nil) | |
if block_given? | |
old_stdout = $stdout | |
output_str = StringIO.new | |
$stdout = output_str | |
begin | |
yield | |
ensure | |
$stdout = old_stdout | |
end | |
str=output_str.string | |
end | |
IO.popen('pbcopy', 'w') { |f| f << str.to_s } unless str.nil? | |
end | |
def paste | |
`pbpaste` | |
end | |
def ep | |
eval(paste) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment