How do I step out of a loop with Ruby Pry?
75,818
Solution 1
To exit Pry unconditionally, type
exit-program
Edit from @Nick's comment: Also works:
!!!
Solution 2
I use:
disable-pry
This will keep the program running, but will keep it from continuing to stop execution. This is especially helpful when you are debugging in the console.
Solution 3
To exit everything, use:
exit!
This should ignore all proceeding bindings.
Solution 4
Triple exclamation (!!!
) would do that.
Solution 5
Use
disable-pry
To renable, add this to your controller
ENV['DISABLE_PRY'] = nil
Related videos on Youtube
Author by
Ryan
Updated on May 19, 2021Comments
-
Ryan about 3 years
I'm using Pry with my Rails application. I set
binding.pry
inside a loop in my model to try and debug a problem. For example:(1..100).each do |i| binding.pry puts i end
When I type
quit
, it goes to the next iteration and stops again. Is there a way to step out of the loop so I don't have to typequit
100 times?Currently the only way I know how to get out of it is to use CTRL+C and restart the application.
-
Ryan almost 12 yearsThanks @Evandro, that is exactly what I was looking for!
-
AJP almost 12 yearsThough you'll obviously hit the binding straight away, using just
exit
will allow the program to keep running. -
Eric Walker almost 11 yearsThis did not work for me when running
rspec
. But CTRL-C, twice, did. -
Ryan almost 11 yearsThis also kills the server at the same time.
exit-program
is still probably the best option if you don't want to restart the server. -
Alan David Garcia over 10 yearsJust to clarify
exit-program
allows you to maintain yourrails server
session but seems to throw aSystemExit
-
stebooks almost 10 yearsTo re-enable (from the command line): ENV['DISABLE_PRY'] = nil
-
daslicious over 9 yearsi was not able to reenter pry after using disable-pry. Even after using ENV['DISABLE_PRY'] = nil
-
Topher Hunt about 9 yearson Mac OSX, pressing
Ctrl + C
twice will kill the Pry session, but will also effectively kill that terminal window: subsequent output is glitched such that I need to close that terminal tab and move to a new one. However!!!
does not have this aggravating effect. -
Radix almost 9 yearsTo reenter pry, all you need to do is to set
ENV['DISABLE_PRY'] = nil
in your controller not in command line OR rails console. -
BBonifield over 8 yearsThis is the perfect one to use when you're using guard and just want it to stop running pry for that test run. It'll reset on the next test run.
-
Sri Harsha Kappala about 8 years@Evandro You have no idea how this saved me!
-
SidOfc about 8 yearsThis was the solution for me on OSX 10.11.4 (El Capitan), I did not try the
disable-pry
+ENV['DISABLE_PRY'] = nil
combo but I did tryexit-program
which gave me a systemExit. This one just works. (On rails 3.2.22.2, pry 0.10.3 and ruby 1.9.3) -
Adamantish almost 8 yearsWarning: If used inside an rspec test it can cause the test to falsely go green. Use the answer by @stebooks instead:
disable-pry
-
vikramvi about 7 yearsIn case somebody struck with * icon shown on pry command with Mac terminal , do single ctrl + C to start using Pry again