Pry Tips and Tricks

Looking at methods

<CookiesController:0x00007f9156c57670>:0> show-method -l

From: /full/path/to/file.rb @ line 78:
Owner: CookiesController
Visibility: private
Number of lines: 37

78: def load_cookie_jar
79: cookies[:tasty] = true
80: count = count_cookies
81: .
.
lots of other code here
.
.

111: require "pry"; binding.pry
112:
113: Repo::FakeClass::NotActuallyAModule.do_something(options)
114: end
<CookiesController:0x00007f9156c57670>:0> show-method Repo::FakeClass::NotActuallyAModule.do_something -l

From: full/path/to/file.rvb @ line 165:
Owner: #<Class:Repo::FakeClass::NotActuallyAModule>
Visibility: public
Number of lines: 22

165: def do_something(options = {})
166: cookies_type = options.fetch(:cookie_type)
167: is_tasty? = options.fetch(:is_valid, false)
168:
169: if is_tasty?
170: log_it "load_cookies", "is_tasty"
171: options[:consumed] = nil
172: options[:pairs_with] = ""
173:
174:
.
.
.
185: end
186: end

Where was I?

View stack traces

<CookiesController:0x00007f9156c57670>:0> not_a_variable
NameError: undefined local variable or method `not_a_variable' for #<CookiesController:0x00007f9156c57670>
from (pry):16:in `load_cookie_jar'
<CookiesController:0x00007f9156c57670>:0> wtf
Exception: NameError: undefined local variable or method `not_a_variable' for #<CookiesController:0x00007f9156c57670>
--
0: (pry):16:in `load_live_action'
1: /Users/joshthompson/.rvm/gems/ruby-2.3.7/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `eval'
2: /Users/joshthompson/.rvm/gems/ruby-2.3.7/gems/pry-0.10.3/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
3: /Users/joshthompson/.rvm/gems/ruby-2.3.7/gems/pry-0.10.3/lib/pry/pry_instance.rb:323:in `handle_line'
4: /Users/joshthompson/.rvm/gems/ruby-2.3.7/gems/pry-0.10.3/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'

Breakpoints in Pry

  • break shows all current breakpoints. (this list should be empty if you’re running break for the first time.
  • break <Class#method> adds a breakpoint to the start of the given method.
# Enabled At
-------------

1 Yes Threatsim::LandingPage::GuidLoader.find_guid

Calling all callers

Additional reading, or articles that helped me learn more about Pry:

--

--

--

Software, rock climbing, books. I love to learn. https://josh.works

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Setting up Selenium WebDriver for Java

MacBook Pro Keyboard with Touchbar with HTML/CSS

ID auto Generate from Laravel Helper

Why Colocation And Data Centers Matter

Free SSL Certificate for GoDaddy using CloudFlare

Installing OrangeHRM on IBM Cloud

Google I/O 17 — What you might have missed

How to setup Buildkite Pipeline on AWS

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
Josh Thompson

Josh Thompson

Software, rock climbing, books. I love to learn. https://josh.works

More from Medium

How to include nested attributes in a Ruby on Rails post request

Binding in Ruby

About Ruby on Rails

ActiveRecord pitfall that could cause a disaster