Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pry: Tips, Tricks, How To

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for Amy Amy
August 15, 2016

Pry: Tips, Tricks, How To

Avatar for Amy

Amy

August 15, 2016

Other Decks in Programming

Transcript

  1. 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
  2. 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)
  3. GETTING STARTED: INSTALLING PRY (IF YOU HAVEN’T OR JUST WANT

    TO AGAIN FOR FUN) • $ gem install pry
  4. RUN SHELL COMMANDS • Preface your commands with a period

    • Examples – . git status – . git diff – . curl http://www.google.com – . cat file.rb
  5. 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
  6. 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
  7. 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!
  8. 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
  9. WTF • Shows you the most recently thrown exception •

    Appeals to the anger or confusion you feel when an Exception is thrown
  10. NESTING • Displays more information about nesting • jump-to –

    Jumps back to any of the previous nesting levels. – Inception problems solved!
  11. 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
  12. 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