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
330
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
230
REPL Driven Development with Pry!
conradirwin
5
1.4k
MongoDB — confessions of a PostgreSQL lover
conradirwin
3
3.3k
Debugging with Pry
conradirwin
0
110
Debuggable Code
conradirwin
1
210
Pry — the good parts!
conradirwin
25
1.6k
Other Decks in Programming
See All in Programming
Vue.js学習の振り返り
hiro_xre
2
130
hotwire_or_react
harunatsujita
8
3.9k
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
C#/.NETのこれまでのふりかえり
tomokusaba
1
150
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
Identifying User Idenity
moro
6
7.5k
CSC509 Lecture 08
javiergs
PRO
0
100
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
150
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
560
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
880
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
140
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.7k
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
167
14k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
How STYLIGHT went responsive
nonsquared
95
5.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.1k
It's Worth the Effort
3n
183
27k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Designing the Hi-DPI Web
ddemaree
280
34k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Faster Mobile Websites
deanohume
304
30k
Into the Great Unknown - MozCon
thekraken
31
1.5k
How to Ace a Technical Interview
jacobian
275
23k
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