This is possible if you started Pry from the command line (that is, by just running pry
), but probably not if you're inside a binding.pry
during another process.
If you started Pry directly, it set up signal handlers and will catch Control+C to return you to the REPL. IRB does the same thing, depending on its ignore_sigint
setting.
But, if you're running inside another process, that process may have set up its own signal handlers. E.g., both rspec
and rails s
watch for Control+C to perform a graceful shutdown. Trying to stop a command inside one of those processes will actually leave Pry open, but perform the process's shutdown work, so as soon as you exit Pry, you're dumped back to the command line.
You can in your Pry session set up your own signal handler, e.g.:
Signal.trap('SIGINT') { puts 'Trapped' }
And there may be something exceedingly clever you can do there to move execution back to the Pry REPL, but it's almost certain to wreak havoc with other handlers that might be in place.