SlideShare a Scribd company logo
1 of 22
Or:
How
I
Learned
To
Stop
Putsing
And
Love
Pry
DEBUGGING RUBY
ABOUT ME
Luke Bergen
Twitter: @lbergen
Reviewed.com
Developers spend 60% of their time
debugging
puts doesn‟t always do the trick
Enter pry and friends
DEBUGGING IN RUBY
“An IRB alternative and runtime
developer console” - http://pryrepl.org
Three major pieces
Pry-core
Pry-custom
Pry-ecosystem
WHAT IS PRY?
Commands are the primary way of
interacting with Pry
Higher order of precedence than ruby code
Expandable
Regex based
PRY-CORE
binding.pry
play
wtf
whereami
? (show-doc)
$ (show-source)
edit
COMMANDS
ls
cd
amend-line
Also !s/foo/bar
.<shell_command>
exit
_
_pry_
_ex_
_in_
_out_
_file_
_dir_
SPECIAL LOCALS
Result of last line
Local pry instance
Last exception
Array of all ruby input expressions
Array of all ruby output results
Last referenced file
Last referenced directory
Pry can be configured by a .pryrc file
~/.pryrc
./.pryrc
Project level pryrc files are especially useful
when paired with custom commands
PRY-CUSTOM
Almost everything in pry is configurable
Some configuration can even be
modified at runtime via _pry_.<config>
Of particular importance/interest:
Editor
Command prefix
Custom commands
BASIC CUSTOMIZATIONS
When using „edit‟ pry uses this setting
If editor is not set, Pry defaults to nano
You can set editor to a proc which
accepts 2 params: file and line
E.g. for sublime text:
EDITOR
COMMAND PREFIX
A problem and a solution
COMMAND PREFIX
A more permanent solution
Pry.config.command_prefix = „%‟
Now all pry commands must be prefixed
with „%‟
CUSTOM COMMANDS
Pry also allows you to define your own
custom commands
By block or class
Useful for often repeated code that
shouldn‟t be checked in
CUSTOM COMMANDS
Suppose you need to clean your
database from time to time
CUSTOM COMMANDS
Programmers are lazy (in a good way)
We like our code DRY and expressive
Where is that laziness when it comes to
the console?
Pry + custom commands = DRY,
expressive console
Any gem whose name fits the format pry-
<plugin> is a plugin
Beware: these gems are auto-loaded by
pry
--no-plugins option will skip auto-loading
.pryrc files get loaded before plugins
Plugin specific suppression:
Pry.plugins[“debugger”].disable!
PRY-ECOSYSTEM (PLUGINS)
Pry-debugger
Works only in MRI 1.8 – 1.9
Pry-byebug
A fork of pry-debugger
Works in MRI 2.0 – 2.1
Pry-nav
Pure ruby implementation
Works on all rubies
DEBUGGERS
Pry-stack-explorer
Gives pry commands: up, down, frame, and show-
stack
Pry-rescue (Pry-exception_explorer has been
deprecated)
Allows you to rescue from exceptions into a pry
session
Rescue for entire program, or only for specified
blocks
Plymouth
Jump into a pry session on test failure
WHEN THINGS BREAK
Uses regex magic to add some easy-access
syntax hackery
Accessing instance variables
foo.@instance_var
Calling private methods
foo.!private_meth()
Examining things in parent pry sessions
puts ../local_var
Just be careful with your regexes
PRY-SYNTAX-HACKS
Pry-doc
Adds core ruby class documentation for “?” and
“$” commands
Pry-vterm_aliases
Makes your ZSH and Bash aliases available to
pry‟s .<shell> command
Pry-theme
Color themes for pry‟s syntax highlighting
MISCELLANEOUS PLUGINS
Pry-rails
Turns rails console into a pry session
Teaches Pry new commands
show-[middleware|model|models|route]
recognize-path
Pry-plus
A pre-packaged group of useful plugins
INTEGRATION
Puts is ok. But don‟t hesitate to drop back and
use the big guns
REPL driven programming is incredibly powerful
Especially when working with new code/library
Explore code
Bundle open your favorite gem when it bugs out (or
just cd into it)
You never know what you‟ll find
CONCLUSION

More Related Content

What's hot

Deconstruct 2017: All programmers MUST learn C and Assembly
Deconstruct 2017: All programmers MUST learn C and AssemblyDeconstruct 2017: All programmers MUST learn C and Assembly
Deconstruct 2017: All programmers MUST learn C and Assemblyice799
 
Do it Yourself Testing
Do it Yourself TestingDo it Yourself Testing
Do it Yourself TestingEmily Stolfo
 
Getting Started with (Distributed) Version Control
Getting Started with (Distributed) Version ControlGetting Started with (Distributed) Version Control
Getting Started with (Distributed) Version ControlJohn Paulett
 
My talk on Piter Py 2016
My talk on Piter Py 2016My talk on Piter Py 2016
My talk on Piter Py 2016Alex Chistyakov
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOpsRicardo Sanchez
 
CRaSH the shell for the JVM
CRaSH the shell for the JVMCRaSH the shell for the JVM
CRaSH the shell for the JVMjviet
 
Brief introduction to kselftest
Brief introduction to kselftestBrief introduction to kselftest
Brief introduction to kselftestSeongJae Park
 
How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?Hiroshi SHIBATA
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineGR8Conf
 
Os Leventhal
Os LeventhalOs Leventhal
Os Leventhaloscon2007
 
20140419 oedo rubykaigi04
20140419 oedo rubykaigi0420140419 oedo rubykaigi04
20140419 oedo rubykaigi04Hiroshi SHIBATA
 
How to write a well-behaved Python command line application
How to write a well-behaved Python command line applicationHow to write a well-behaved Python command line application
How to write a well-behaved Python command line applicationgjcross
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerThe Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerVladimir Sedach
 
Plumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshopPlumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshopStefan Baumgartner
 

What's hot (20)

20140918 ruby kaigi2014
20140918 ruby kaigi201420140918 ruby kaigi2014
20140918 ruby kaigi2014
 
Deconstruct 2017: All programmers MUST learn C and Assembly
Deconstruct 2017: All programmers MUST learn C and AssemblyDeconstruct 2017: All programmers MUST learn C and Assembly
Deconstruct 2017: All programmers MUST learn C and Assembly
 
Do it Yourself Testing
Do it Yourself TestingDo it Yourself Testing
Do it Yourself Testing
 
Getting Started with (Distributed) Version Control
Getting Started with (Distributed) Version ControlGetting Started with (Distributed) Version Control
Getting Started with (Distributed) Version Control
 
My talk on Piter Py 2016
My talk on Piter Py 2016My talk on Piter Py 2016
My talk on Piter Py 2016
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
 
CRaSH the shell for the JVM
CRaSH the shell for the JVMCRaSH the shell for the JVM
CRaSH the shell for the JVM
 
Brief introduction to kselftest
Brief introduction to kselftestBrief introduction to kselftest
Brief introduction to kselftest
 
Composer Helpdesk
Composer HelpdeskComposer Helpdesk
Composer Helpdesk
 
How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?How to develop the Standard Libraries of Ruby?
How to develop the Standard Libraries of Ruby?
 
CPAN Training
CPAN TrainingCPAN Training
CPAN Training
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual Machine
 
Slack Bots in Ruby
Slack Bots in RubySlack Bots in Ruby
Slack Bots in Ruby
 
Os Leventhal
Os LeventhalOs Leventhal
Os Leventhal
 
20140419 oedo rubykaigi04
20140419 oedo rubykaigi0420140419 oedo rubykaigi04
20140419 oedo rubykaigi04
 
How to write a well-behaved Python command line application
How to write a well-behaved Python command line applicationHow to write a well-behaved Python command line application
How to write a well-behaved Python command line application
 
20140925 rails pacific
20140925 rails pacific20140925 rails pacific
20140925 rails pacific
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerThe Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compiler
 
Plumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshopPlumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshop
 
The problem with Perl
The problem with PerlThe problem with Perl
The problem with Perl
 

Similar to Debugging Ruby (with Pry)

Exploring Code with Pry!
Exploring Code with Pry!Exploring Code with Pry!
Exploring Code with Pry!Clayton Parker
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
2009 cluster user training
2009 cluster user training2009 cluster user training
2009 cluster user trainingChris Dwan
 
Rails 勉強会#3
Rails 勉強会#3Rails 勉強会#3
Rails 勉強会#3masami ito
 
Docker Introduction.pdf
Docker Introduction.pdfDocker Introduction.pdf
Docker Introduction.pdfOKLABS
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90minsLarry Cai
 
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonChris Charlton
 
Using puppet
Using puppetUsing puppet
Using puppetAlex Su
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with PuppetAlessandro Franceschi
 
Learn enough Docker to be dangerous
Learn enough Docker to be dangerousLearn enough Docker to be dangerous
Learn enough Docker to be dangerousDavid Tan
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Workhorse Computing
 
Using filesystem capabilities with rsync
Using filesystem capabilities with rsyncUsing filesystem capabilities with rsync
Using filesystem capabilities with rsyncHazel Smith
 
Docker jako prostředí pro automatizaci testů
Docker jako prostředí pro automatizaci testůDocker jako prostředí pro automatizaci testů
Docker jako prostředí pro automatizaci testůRadim Daniel Pánek
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureHabeeb Rahman
 
Docker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesDocker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesSujay Pillai
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slidesDocker, Inc.
 

Similar to Debugging Ruby (with Pry) (20)

Exploring Code with Pry!
Exploring Code with Pry!Exploring Code with Pry!
Exploring Code with Pry!
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Daemons in PHP
Daemons in PHPDaemons in PHP
Daemons in PHP
 
REPL-driven development with pry
REPL-driven development with pry  REPL-driven development with pry
REPL-driven development with pry
 
2009 cluster user training
2009 cluster user training2009 cluster user training
2009 cluster user training
 
Rails 勉強会#3
Rails 勉強会#3Rails 勉強会#3
Rails 勉強会#3
 
Docker Introduction.pdf
Docker Introduction.pdfDocker Introduction.pdf
Docker Introduction.pdf
 
Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris CharltonDrush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
 
Using puppet
Using puppetUsing puppet
Using puppet
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Learn enough Docker to be dangerous
Learn enough Docker to be dangerousLearn enough Docker to be dangerous
Learn enough Docker to be dangerous
 
Intro django
Intro djangoIntro django
Intro django
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
Using filesystem capabilities with rsync
Using filesystem capabilities with rsyncUsing filesystem capabilities with rsync
Using filesystem capabilities with rsync
 
Docker jako prostředí pro automatizaci testů
Docker jako prostředí pro automatizaci testůDocker jako prostředí pro automatizaci testů
Docker jako prostředí pro automatizaci testů
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
 
Docker Basics & Alfresco Content Services
Docker Basics & Alfresco Content ServicesDocker Basics & Alfresco Content Services
Docker Basics & Alfresco Content Services
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 

Recently uploaded

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Recently uploaded (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Debugging Ruby (with Pry)

  • 2. ABOUT ME Luke Bergen Twitter: @lbergen Reviewed.com
  • 3. Developers spend 60% of their time debugging puts doesn‟t always do the trick Enter pry and friends DEBUGGING IN RUBY
  • 4. “An IRB alternative and runtime developer console” - http://pryrepl.org Three major pieces Pry-core Pry-custom Pry-ecosystem WHAT IS PRY?
  • 5. Commands are the primary way of interacting with Pry Higher order of precedence than ruby code Expandable Regex based PRY-CORE
  • 7. _ _pry_ _ex_ _in_ _out_ _file_ _dir_ SPECIAL LOCALS Result of last line Local pry instance Last exception Array of all ruby input expressions Array of all ruby output results Last referenced file Last referenced directory
  • 8. Pry can be configured by a .pryrc file ~/.pryrc ./.pryrc Project level pryrc files are especially useful when paired with custom commands PRY-CUSTOM
  • 9. Almost everything in pry is configurable Some configuration can even be modified at runtime via _pry_.<config> Of particular importance/interest: Editor Command prefix Custom commands BASIC CUSTOMIZATIONS
  • 10. When using „edit‟ pry uses this setting If editor is not set, Pry defaults to nano You can set editor to a proc which accepts 2 params: file and line E.g. for sublime text: EDITOR
  • 11. COMMAND PREFIX A problem and a solution
  • 12. COMMAND PREFIX A more permanent solution Pry.config.command_prefix = „%‟ Now all pry commands must be prefixed with „%‟
  • 13. CUSTOM COMMANDS Pry also allows you to define your own custom commands By block or class Useful for often repeated code that shouldn‟t be checked in
  • 14. CUSTOM COMMANDS Suppose you need to clean your database from time to time
  • 15. CUSTOM COMMANDS Programmers are lazy (in a good way) We like our code DRY and expressive Where is that laziness when it comes to the console? Pry + custom commands = DRY, expressive console
  • 16. Any gem whose name fits the format pry- <plugin> is a plugin Beware: these gems are auto-loaded by pry --no-plugins option will skip auto-loading .pryrc files get loaded before plugins Plugin specific suppression: Pry.plugins[“debugger”].disable! PRY-ECOSYSTEM (PLUGINS)
  • 17. Pry-debugger Works only in MRI 1.8 – 1.9 Pry-byebug A fork of pry-debugger Works in MRI 2.0 – 2.1 Pry-nav Pure ruby implementation Works on all rubies DEBUGGERS
  • 18. Pry-stack-explorer Gives pry commands: up, down, frame, and show- stack Pry-rescue (Pry-exception_explorer has been deprecated) Allows you to rescue from exceptions into a pry session Rescue for entire program, or only for specified blocks Plymouth Jump into a pry session on test failure WHEN THINGS BREAK
  • 19. Uses regex magic to add some easy-access syntax hackery Accessing instance variables foo.@instance_var Calling private methods foo.!private_meth() Examining things in parent pry sessions puts ../local_var Just be careful with your regexes PRY-SYNTAX-HACKS
  • 20. Pry-doc Adds core ruby class documentation for “?” and “$” commands Pry-vterm_aliases Makes your ZSH and Bash aliases available to pry‟s .<shell> command Pry-theme Color themes for pry‟s syntax highlighting MISCELLANEOUS PLUGINS
  • 21. Pry-rails Turns rails console into a pry session Teaches Pry new commands show-[middleware|model|models|route] recognize-path Pry-plus A pre-packaged group of useful plugins INTEGRATION
  • 22. Puts is ok. But don‟t hesitate to drop back and use the big guns REPL driven programming is incredibly powerful Especially when working with new code/library Explore code Bundle open your favorite gem when it bugs out (or just cd into it) You never know what you‟ll find CONCLUSION

Editor's Notes

  1. Let’s be honest. The vast majority of the time, “puts the_thing_that_makes_no_sense” is completely sufficient to figure out what’s going wrong in your programI don’t believe that we spend 60% of our time debugging the kinds of problems that can be solved with a puts
  2. Also, these are useful
  3. Some plugins like the debuggers hook into the Pryinit process so using pryrc suppression won’t always save the day.
  4. Demonstration of bug running ./todo.rb items buggy_list