Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created October 6, 2017 12:27
Show Gist options
  • Select an option

  • Save troelskn/e65439a10faf7fc81c757d766814aee4 to your computer and use it in GitHub Desktop.

Select an option

Save troelskn/e65439a10faf7fc81c757d766814aee4 to your computer and use it in GitHub Desktop.
Drop into an IRB session from within a rake task
desc "Start an interactive console"
task :console do
require "irb"
require "irb/completion"
require "pp"
ARGV.clear
IRB.setup(nil)
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history"
irb = IRB::Irb.new
irb.context.inspect_mode = IRB::Inspector.new(proc{ |v| v.pretty_inspect.chomp })
IRB.conf[:MAIN_CONTEXT] = irb.context
trap "SIGINT" do
irb.signal_handle
end
begin
catch :IRB_EXIT do
irb.eval_input
end
ensure
IRB.irb_at_exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment