Debugging your code with Pry.

What is Pry?

Pry is a debugging tool that Ruby developers use to debug their code.

How does Pry work?

In the example below, we created a method where we set x to a value of 3, y to a value of 5, and z to the sum of x and y.

require 'pry'def example  x = 3  y = 5  binding.pry  z = x + y  binding.pry  puts zendexample
4: def example
5:
6: x = 3
7: y = 5
=> 8: binding.pry
9: z = x + y
10: binding.pry
11: puts z
12:
13: end
[1] pry(main)>
[1] pry(main)> x
=> 3
[2] pry(main)> y
=> 5
[3] pry(main)> y - x
=> 2
[4] pry(main)> z
=> nil
[5] pry(main)>
4: def example
5:
6: x = 3
7: y = 5
8: binding.pry
9: z = x + y
=> 10: binding.pry
11: puts z
12:
13: end
[1] pry(main)>
[1] pry(main)> z
=> 8
[2] pry(main)>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store