When I debug rails code, I sometimes set a binding.pry
on a certain place that is triggered too often to be debugged, eg a loop.
Then I use the disable-pry
command to step out of it and let the rest of the program continue. But now when I make another request to the rails server, my breakpoints aren't triggered anymore. And this of course makes sense, as I called disable-pry
before.
The only known solution to me is to restart the whole server. But this becomes painful after a while, as reloading the whole environment can be pretty slow.
Is there a way to re-enable pry after having it disabled with disable-pry
without restarting the whole ruby process?
Use ENV['DISABLE_PRY'] = nil
or ENV.delete('DISABLE_PRY')
to reverse what disable-pry
does.
As of version 0.13, this is what the method disable-pry
looks like.
[1] pry(main)> show-method disable-pry
From: /app/vendor/ruby/3.1.0/gems/pry-0.13.1/lib/pry/commands/disable_pry.rb Number of lines: 23
class DisablePry < Pry::ClassCommand
match 'disable-pry'
group 'Navigating Pry'
description 'Stops all future calls to pry and exits the current session.'
banner <<-'BANNER'
Usage: disable-pry
After this command is run any further calls to pry will immediately return `nil`
without interrupting the flow of your program. This is particularly useful when
you've debugged the problem you were having, and now wish the program to run to
the end.
As alternatives, consider using `exit!` to force the current Ruby process
to quit immediately; or using `edit -p` to remove the `binding.pry`
from the code.
BANNER
def process
ENV['DISABLE_PRY'] = 'true'
pry_instance.run_command "exit"
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.