ENGINEERING SATURDAYS – PRY THE REPL



ENGINEERING SATURDAYS – PRY THE REPL

1 1


pry-presentation

Slides from Engineering Saturdays - PRY

On Github akhilstanislavose / pry-presentation

ENGINEERING SATURDAYS

PRY THE REPL

August  4,  2012 akhil stanislavose - akhil@mobme.in

What is PRY?

Pry is a powerful alternative to the standard IRB shell for Ruby.

PRY AS A DEBUGGER

def my_method
  # some super code

  # break point
  binding.pry

  # more super code
end
            

NAVIGATION AROUND STATE

# cd into a module, class, or an object.
[1] pry(main)> cd String
[2] pry(main)> cd Enumerable
[3] pry(main)> cd "Hi, I am a String object"

# ls the current context
[4] pry(String)> ls

# list only sigleton instance methods
[5] pry(String)> ls -qm
            

SOURCE/DOC BROWSING

# Search for a method
[1] pry(main)> find-method method_name [Scope]

# Get documentation for a method/class/module
[2] pry(main)> show-doc String::tabelize
[3] pry(main)> stat String::tabelize

# Show source of a method/class/module
[4] pry(main)> show-source String::tabelize

            

INPUT MANIPULATION

# Show the input buffer
[1] pry(main)> show-input

# Edit a line in input buffer
[2] pry(main)> amend-line [line_no|startln..endln] new line

# Delete a line in input buffer
[3] pry(main)> amend-line line_no [line_no|startln..endln] !

# Fire up your editor to enter long code in to console
[4] pry(main)> edit

# Show history
[4] pry(main)> history [--tail | --head | --replay]
            

SHELL INTEGRATION

# exectue any commad in shell from pry
[1] pry(main)> .<any-shell-cpmmand>
[2] pry(main)> .ls

# String interpolation in shell commands
[3] pry(main)> .cd #{dir_path}

# PRYs own cat with syntax highlight for source files
[4] pry(main)> cat source.rb

# Use shell-mode to make your prompt more like you shell prompt
[4] pry(main)> shell-mode
            

What else can it do?

  • Gist Support - publish gists from PRY
  • Exception Handling - track and inspect exceptions
  • Customize and Configure
  • Plugins - extend PRY
  • Remote Sessions

HOW TO GET HELP?

Every pry command has a --help flag. And to see the list of all pry commands just run the help command.

https://github.com/pry/pry/wiki

THE END

(Questions ?)