This is a quick reference guide for using ‘pry’ gem for debugging Ruby code.
gem list pry: lists whether it is already installed
gem install pry: installs the pry gem
- insert the above line at the top of the ruby file you intend to debug
- insert the above line to stop execution at a particular point in the code
- insert this after the line where you want to pause the program execution
- run the program
- type the debugging stuff (variable names, method names etc.) once the program pauses
- type ‘step’ to go to the next line
- use the above key combo to move to the next ‘binding.pry’ statement in the program
Here’s a good screen cast describing the debugging features of Pry.
However, debugging is just one of the many things that can be done using Pry. One other main feature is replacing IRB. A good reference page (with screen-casts and all) can be found here.