Skip to content
John Mair edited this page Aug 14, 2011 · 11 revisions

Live help system

### Quick Menu:

Back to Main Menu

Overview

One of the design goals of Pry was for it to be self-documenting. To that end, Pry provides commands that yield documentation on nearly every aspect of Pry from within the REPL itself.

### Viewing a Pry method's documentation

Since Pry is simply Ruby code, all documentation on its methods are available using the standard show-doc command.

Example:

pry(main)> ? Pry#valid_expression?

From: /Users/john/.rvm/gems/ruby-1.9.2-p180/gems/pry-0.9.2/lib/pry/pry_instance.rb @ line 458:
Number of lines: 7

signature: valid_expression?(code)

Determine if a string of code is a valid Ruby expression.
Ruby 1.9 uses Ripper, Ruby 1.8 uses RubyParser.
param [String] code The code to validate.
return [Boolean] Whether or not the code is a valid Ruby expression.
example
  valid_expression?("class Hello") #=> false
  valid_expression?("class Hello; end") #=> true
pry(main)>

Back to top

### Learning about Pry's configuration options

Live help may be particularly useful when learning about Pry's configuration options. Most of these are documented methods in the Pry.config namespace.

Example:

pry(main)> ls -m Pry.config
[:__binding_impl__, :color, :color=, :commands, :commands=, :editor, :editor=, :exception_handler, :exception_handler=, :has_pry_doc, :has_pry_doc=, :history, :history=, :hooks, :hooks=, :input, :input=, :memory_size, :memory_size=, :output, :output=, :pager, :pager=, :plugins, :plugins=, :print, :print=, :prompt, :prompt=, :result_pager, :result_pager=, :results_pager, :results_pager=, :should_load_plugins, :should_load_plugins=, :should_load_rc, :should_load_rc=]
pry(main)> ? Pry.config.editor

From: /Users/john/.rvm/gems/ruby-1.9.2-p180/gems/pry-0.9.2/lib/pry/config.rb @ line 58:
Number of lines: 12

signature: editor()

The default editor to use. Defaults to $EDITOR or nano if
$EDITOR is not defined.
If editor is a String then that string is used as the shell
command to invoke the editor. If editor is callable (e.g a
Proc) then file and line are passed in as parameters and the
return value of that callable invocation is used as the exact
shell command to invoke the editor.
example String
  Pry.editor = "emacsclient"
example Callable
  Pry.editor = proc { |file, line| "emacsclient #{file} +#{line}" }
return [String, #call]
pry(main)>

Back to top

### The `help` command (Pry command documentation)

Pry's commands are not methods and so cannot easily be documented in the same way as methods (using show-doc). Instead commands have their own documentation system organized around the help command.

Typing help at the prompt will retrieve a list of all available commands. If you pass a parameter to help where that parameter is the name of a command you will restrict the output to the help for just that command.

Note that help only returns a short description of each command, but this is sufficient in many cases. For more complex commands the description (retrieved by help) will indicate that more documentation is available by passing the --help switch to the command itself.

Example: A simple command

pry(main)> help cd
Start a Pry session on VAR (use `cd ..` to go back and `cd /` to return to Pry top-level)
pry(main)>

Example: A command with further documentation available

pry(main)> help show-method
Show the source for METH. Type `show-method --help` for more info. Aliases: $, show-source
pry(main)> show-method --help
Usage: show-method [OPTIONS] [METH]
Show the source for method METH. Tries instance methods first and then methods by default.
e.g: show-method hello_method

options:

    -l, --line-numbers          Show line numbers.
    -b, --base-one              Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands).
    -M, --instance-methods      Operate on instance methods.
    -m, --methods               Operate on methods.
    -f, --flood                 Do not use a pager to view text longer than one screen.
    -c, --context               Select object context to run under.
    -h, --help                  This message.
pry(main)>

Back to top