Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Efficient debugging with Pry
Search
Conrad Irwin
October 02, 2012
Programming
2
360
Efficient debugging with Pry
A short talk summarizing how to use Pry to save yourself time when debugging.
Conrad Irwin
October 02, 2012
Tweet
Share
More Decks by Conrad Irwin
See All by Conrad Irwin
Go for Rubyists
conradirwin
2
260
REPL Driven Development with Pry!
conradirwin
5
1.5k
MongoDB — confessions of a PostgreSQL lover
conradirwin
3
3.6k
Debugging with Pry
conradirwin
0
120
Debuggable Code
conradirwin
1
240
Pry — the good parts!
conradirwin
25
1.6k
Other Decks in Programming
See All in Programming
Java on Azure で LangGraph!
kohei3110
0
160
ReadMoreTextView
fornewid
1
450
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
250
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
120
コード書くの好きな人向けAIコーディング活用tips #orestudy
77web
3
330
Passkeys for Java Developers
ynojima
3
880
CursorはMCPを使った方が良いぞ
taigakono
0
140
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
110
Perplexity Slack Botを作ってAI活用を進めた話 / AI Engineering Summit プレイベント
n3xem
0
670
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
320
Enterprise Web App. Development (2): Version Control Tool Training Ver. 5.1
knakagawa
1
120
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
150
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Making the Leap to Tech Lead
cromwellryan
134
9.3k
KATA
mclloyd
29
14k
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.4k
Typedesign – Prime Four
hannesfritz
42
2.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
The Language of Interfaces
destraynor
158
25k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
660
Facilitating Awesome Meetings
lara
54
6.4k
Transcript
None
Debugging l Figure out why the code is broken l
Fix it l Repeat.
puts l Most common debugging tool l Very easy to
use l Gather information one chunk at a time
binding.pry l Opens pry at that line in your code
l `gem install pry` l Gather as much information as you need l Test theories immediately
pry-rescue l Automatic binding.pry on unhandled exceptions l `gem install
pry-rescue` l Reduces feedback cycle times
NoMethodError l Most common exception in ruby code? l Caused
by: - Typos - Forgetting the right method name - Using the wrong object
ls -‐-‐grep l Finds the correct method l No
need to google l Doesn't rely on gems having docs ;)
[1] pry(main)> ls Base64 -‐-‐grep encode Base64.methods:
encode64 strict_encode64 urlsafe_encode64 [2] pry(main)>
ls -‐-‐grep l Finds the correct method l No
need to google l Doesn't rely on gems having docs ;)
edit -‐-‐ex l Opens your text editor l Jumps
to the exception l Reloads the code when you're done
From: /0/ruby/pry/example.rb @ line 3: 3:
def base64ify(email) => 4: Base64.encode(email) 5: end NoMethodError: undefined method `encode' for Base64:Module' [1] pry(main)>
From: /0/ruby/pry/example.rb @ line 3: 3:
def base64ify(email) => 4: Base64.encode(email) 5: end NoMethodError: undefined method `encode' for Base64:Module' [1] pry(main)> edit -‐-‐ex
None
[1] pry(main)> edit -‐-‐ex 3: def
base64ify(email) => 4: Base64.encode64(email) 5: end [2] pry(main)> base64ify("hello world") "aGVsbG8gd29ybGQ=\n"
up and down l Moves pry up and down the
call stack l Figure out why you have the wrong object l Discover why a gem doesn't work l `gem install pry-stack_explorer`
From: /0/ruby/pry/example2.rb @ line 2: 2:
def make_safe(text) => 3: text.gsub(/[^a-‐z]/i, '-‐') 4: end NoMethodError: undefined method `gsub' for nil:NilClass' [1] pry(main)>
[1] pry(main)> up From: /0/ruby/pry/example2.rb @ line 6:
2: def safe_title(post) => 3: make_safe(post[:title]) 4: end [2] pry(main)> post {"title" => "Hello Pry"}
up and down l Moves pry up and down the
call stack l Figure out why you have the wrong object l Discover why a gem doesn't work l `gem install pry-stack_explorer`
$ and ? l show-source and show-doc l Instant documentation
when you need it l No need to `cd` into gem directories.
[1] pry(main)> $ safe_title 2: def
safe_title(post) 3: make_safe(post[:title]) 4: end [2] pry(main)>
[2] pry(main)> ? safe_title Convert the title of the
blog into a string suitable for use in URLs. param [Hash] post return [String] [3] pry(main)>
In conclusion l Debugging requires gathering information l Get into
a `binding.pry` habit l Explore pry's extra features - gem install pry-full - Type `help` inside pry
<EOF> l @ConradIrwin (github, twitter, gmail, etc.) l http://pryrepl.org/ l
irc://freenode.net/#pry