Share
Embed
Transcript
23 slides
-
CURRENTLY A DEVELOPER @ An Electronic Medical Records Software aimed
at Substance Abuse facilities -
SO…WHAT IS PRY AND WHY SHOULD I CARE? • The
WHAT: – Ruby Gem – A well known alternative to the standard IRB shell for Ruby – A runtime developer console for Ruby • The WHY SHOULD I CARE? – Because you’re at a talk about Pry – Also, it’s a powerful tool for debugging -
PRY CAN HELP • Pry is your friend! • Debugging
is a huge part of our job as Developers – Developers spend 60% of their time debugging – The faster we can debug, the faster we can get back to Reddit! • Many are familiar with ‘binding.pry’ but don’t use Pry to its potential – This method starts a Pry session and pauses the code execution – Think of it as opening the Rails console (at a chosen point in the execution path) -
GETTING STARTED: INSTALLING PRY (IF YOU HAVEN’T OR JUST WANT
TO AGAIN FOR FUN) • $ gem install pry -
RUN SHELL COMMANDS • Preface your commands with a period
• Examples – . git status – . git diff – . curl http://www.google.com – . cat file.rb -
INPUT BUFFER • ! – Clears the input buffer –
Breaks out of the read loop -- doing this will enable normal input to resume on the next line. • show-input – Useful when entering long multi-line expressions • amend-line – amend-line line# – amend-line line#range • edit – edit class/method/etc • Opens temp pry file in default editor -
MORE ON EDIT • When you run edit inside a
pry window, it opens up a temporary file for editing. • The editor of choice can be configured in the ~/.pryrc with the directive Pry.config.editor = 'vim'. • Once you save the file and close it, it gets run by the pry session and you can access whatever elements you define inside of it. • How to use it: – edit sample.rb # Specific file – edit sample.rb --line 105 # Specific line – edit MyClass # Edit by class – edit MyClass#my_method # Specific method – edit --ex # Edit the file that raised the most recent exception -
RUN RUBY CODE WITH PRY • Instead of: – ruby
awesome_code.rb • Use: – pry awesome_code.rb • Will even start an interactive session if an exception is encountered! -
CD & LS • Navigate objects like you would directories
in your terminal • How to: – cd Object – cd .. – ls • Lists out methods available to the current scope and other useful info • -i flag will list out instance variables if any -
WTF • Shows you the most recently thrown exception •
Appeals to the anger or confusion you feel when an Exception is thrown -
NESTING • Displays more information about nesting • jump-to –
Jumps back to any of the previous nesting levels. – Inception problems solved! -
WHEREAMI • For when you’re confused/forgot you can use the
nesting command -
PLAY LINES • play –l – Can run specific lines
of code or ranges of lines of code • Example: – Place a binding.pry somewhere in your code – Can now play subsequent lines of code -
SHOW-DOC • Alias: ? • Example – ? Array#map –
? binding – ? Pry -
SHOW-SOURCE • Alias: $ • Examples – $ Array#map –
$ binding – $ Pry -
RESOURCES • We’ve barely scratched the surface – Pry is
highly configurable – Many helpful plugins you can use in tandem to level up your debugging skills • Resources: – Pry wiki: https://github.com/pry/pry/wiki – Pry docs: http://www.rubydoc.info/github/pry/pry/master/Pry – Available Pry Plugins: https://github.com/pry/pry/wiki/Available-plugins