Skip to content

Instantly share code, notes, and snippets.

@kbrock
Created June 5, 2009 13:25
Show Gist options
  • Save kbrock/124279 to your computer and use it in GitHub Desktop.
Save kbrock/124279 to your computer and use it in GitHub Desktop.
copy an irb command to clipboard
copy {
puts "puts 'hello world'"
}
#command V
ep
# 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