Created
October 6, 2017 12:27
-
-
Save troelskn/e65439a10faf7fc81c757d766814aee4 to your computer and use it in GitHub Desktop.
Drop into an IRB session from within a rake task
This file contains hidden or 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
| 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