Class Pry
In: lib/pry.rb
lib/pry/cli.rb
lib/pry/code.rb
lib/pry/command.rb
lib/pry/command_set.rb
lib/pry/commands.rb
lib/pry/completion.rb
lib/pry/config.rb
lib/pry/custom_completions.rb
lib/pry/default_commands/cd.rb
lib/pry/default_commands/commands.rb
lib/pry/default_commands/context.rb
lib/pry/default_commands/easter_eggs.rb
lib/pry/default_commands/editing.rb
lib/pry/default_commands/find_method.rb
lib/pry/default_commands/gems.rb
lib/pry/default_commands/gist.rb
lib/pry/default_commands/help.rb
lib/pry/default_commands/hist.rb
lib/pry/default_commands/input_and_output.rb
lib/pry/default_commands/introspection.rb
lib/pry/default_commands/ls.rb
lib/pry/default_commands/misc.rb
lib/pry/default_commands/navigating_pry.rb
lib/pry/default_commands/whereami.rb
lib/pry/extended_commands/experimental.rb
lib/pry/helpers/base_helpers.rb
lib/pry/helpers/command_helpers.rb
lib/pry/helpers/documentation_helpers.rb
lib/pry/helpers/options_helpers.rb
lib/pry/helpers/text.rb
lib/pry/history.rb
lib/pry/history_array.rb
lib/pry/hooks.rb
lib/pry/indent.rb
lib/pry/method.rb
lib/pry/module_candidate.rb
lib/pry/plugins.rb
lib/pry/pry_class.rb
lib/pry/pry_instance.rb
lib/pry/rbx_method.rb
lib/pry/rbx_path.rb
lib/pry/repl_file_loader.rb
lib/pry/version.rb
lib/pry/wrapped_module.rb
Parent: Object

Pry is a powerful alternative to the standard IRB shell for Ruby. It features syntax highlighting, a flexible plugin architecture, runtime invocation and source and documentation browsing.

Pry can be started similar to other command line utilities by simply running the following command:

    pry

Once inside Pry you can invoke the help message:

    help

This will show a list of available commands and their usage. For more information about Pry you can refer to the following resources:

Methods

Included Modules

ModuleIntrospectionHelpers

Classes and Modules

Module Pry::DefaultCommands
Module Pry::ExtendedCommands
Module Pry::Helpers
Module Pry::InputCompleter
Module Pry::RbxMethod
Module Pry::RbxPath
Class Pry::BlockCommand
Class Pry::CLI
Class Pry::ClassCommand
Class Pry::Code
Class Pry::Command
Class Pry::CommandSet
Class Pry::Config
Class Pry::History
Class Pry::HistoryArray
Class Pry::Hooks
Class Pry::Indent
Class Pry::Method
Class Pry::NoCommandError
Class Pry::PluginManager
Class Pry::REPLFileLoader
Class Pry::Result
Class Pry::WrappedModule

Constants

DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_| next if _pry_.quiet?   The default hooks - display messages when beginning and ending Pry sessions.
Commands = Pry::CommandSet.new do import DefaultCommands::Misc   Default commands used by Pry.
DEFAULT_CUSTOM_COMPLETIONS = proc { commands.commands.keys }   This proc will be instance_eval‘s against the active Pry instance
FILE_COMPLETIONS = proc { commands.commands.keys + Dir.entries('.') }
RC_FILES = ["~/.pryrc"]   The RC Files to load.
LOCAL_RC_FILE = "./.pryrc"
VERSION = "0.9.10"

External Aliases

quiet -> quiet?

Attributes

backtrace  [RW] 
binding_stack  [RW] 
cli  [RW]  @return [Boolean] Whether Pry was activated from the command line.
command_state  [R]  This is exposed via Pry::Command#state.
commands  [RW] 
config  [RW]  @return [OpenStruct] Return Pry‘s config object.
current_line  [RW]  @return [Fixnum] The current input line.
custom_completions  [RW]  Get/Set the Proc that defines extra Readline completions (on top of the ones defined for IRB). @return [Proc] The Proc that defines extra Readline completions (on top @example Add file names to completion list
  Pry.custom_completions = proc { Dir.entries('.') }
custom_completions  [RW] 
eval_path  [RW]  @return [String] The FILE for the `eval()`. Should be "(pry)"
  by default.
exception_handler  [RW] 
extra_sticky_locals  [RW] 
history  [RW]  @return [History] Return Pry‘s line history object.
hooks  [R]  Special treatment for hooks as we want to alert people of the changed API
input  [RW] 
input_array  [R] 
input_stack  [RW] 
last_dir  [RW] 
last_exception  [R] 
last_file  [RW] 
last_result  [RW] 
line_buffer  [RW]  @return [Array] The Array of evaluated expressions.
output  [RW] 
output_array  [R] 
print  [RW] 
quiet  [RW]  @return [Boolean] Whether Pry sessions are quiet by default.
quiet  [RW] 
suppress_output  [RW] 
toplevel_binding  [RW]  @return [Binding] A top level binding with no local variables

Public Class methods

Convert the given object into an instance of `Pry::Code`, if it isn‘t already one.

@param [Code, Method, UnboundMethod, Proc, Pry::Method, String, Array,

  IO] obj

If the given object is a `Pry::Method`, return it unaltered. If it‘s anything else, return it wrapped in a `Pry::Method` instance.

If the given object is a `Pry::WrappedModule`, return it unaltered. If it‘s anything else, return it wrapped in a `Pry::WrappedModule` instance.

Return a `Binding` object for `target` or return `target` if it is already a `Binding`. In the case where `target` is top-level then return `TOPLEVEL_BINDING` @param [Object] target The object to get a `Binding` object for. @return [Binding] The `Binding` object.

To avoid mass-confusion, we change the default colour of "white" to "blue" enabling global legibility

Basic initialization.

@return [Boolean] Whether this is the first time a Pry session has

  been started since loading the Pry class.

Do basic setup for initial session. Including: loading .pryrc, loading plugins, loading requires, and loading history.

Load the given file in the context of `Pry.toplevel_binding` @param [String] file_name The unexpanded file path.

Execute the file through the REPL loop, non-interactively. @param [String] file_name File name to load through the REPL.

Load Readline history if required.

Load the local RC file (./.pryrc)

Load the rc files given in the `Pry::RC_FILES` array. This method can also be used to reload the files if they have changed.

Load any Ruby files specified with the -r flag on the command line.

Trap interrupts on jruby, and make them behave like MRI so we can catch them.

Create a new `Pry` object. @param [Hash] options The optional configuration parameters. @option options [readline] :input The object to use for input. @option options [puts] :output The object to use for output. @option options [Pry::CommandBase] :commands The object to use for commands. @option options [Hash] :hooks The defined hook Procs @option options [Array<Proc>] :prompt The array of Procs to use for the prompts. @option options [Proc] :print The Proc to use for the ‘print’ @option options [Boolean] :quiet If true, omit the whereami banner when starting.

  component of the REPL. (see print.rb)

Set all the configurable options back to their default values

Run a Pry command from outside a session. The commands available are those referenced by `Pry.commands` (the default command set). @param [String] command_string The Pry command (including arguments,

  if any).

@param [Hash] options Optional named parameters. @return [Object] The return value of the Pry command. @option options [Object, Binding] :context The object context to run the

  command under. Defaults to `TOPLEVEL_BINDING` (main).

@option options [Boolean] :show_output Whether to show command

  output. Defaults to true.

@example Run at top-level with no output.

  Pry.run_command "ls"

@example Run under Pry class, returning only public methods.

  Pry.run_command "ls -m", :context => Pry

@example Display command output.

  Pry.run_command "ls -av", :show_output => true

Save new lines of Readline history if required.

Start a Pry REPL. This method also loads the files specified in `Pry::RC_FILES` the first time it is invoked. @param [Object, Binding] target The receiver of the Pry session @param [Hash] options @option options (see Pry#initialize) @example

  Pry.start(Object.new, :input => MyInput.new)

An inspector that clips the output to `max_length` chars. In case of > `max_length` chars the `#<Object…> notation is used. @param obj The object to view. @param max_length The maximum number of chars before clipping occurs. @return [String] The string representation of `obj`.

Public Instance methods

Add a sticky local to this Pry instance. A sticky local is a local that persists between all bindings in a session. @param [Symbol] name The name of the sticky local. @yield The block that defines the content of the local. The local

  will be refreshed at each tick of the repl loop.

The currently active `Binding`. @return [Binding] The currently active `Binding` for the session.

Execute the specified hook. @param [Symbol] name The hook name to execute @param [*Object] args The arguments to pass to the hook @return [Object, Exception] The return value of the hook or the exception raised

If executing a hook raises an exception, we log that and then continue sucessfully. To debug such errors, use the global variable $pry_hook_error, which is set as a result.

FIXME: This is a hack to alert people of the new API. @param [Pry::Hooks] v Only accept `Pry::Hooks` now!

Injects a local variable into the provided binding. @param [String] name The name of the local to inject. @param [Object] value The value to set the local to. @param [Binding] b The binding to set the local on. @return [Object] The value the local was set to.

Inject all the sticky locals into the `target` binding. @param [Binding] target

Set the last exception for a session. @param [Exception] ex

@return [Boolean] True if the last result is an exception that was raised,

  as opposed to simply an instance of Exception (like the result of
  Exception.new)

@return [Integer] The maximum amount of objects remembered by the inp and

  out arrays. Defaults to 100.

Pops the current prompt off of the prompt stack. If the prompt you are popping is the last prompt, it will not be popped. Use this to restore the previous prompt. @return [Array<Proc>] Prompt being popped. @example

   prompt1 = [ proc { '>' }, proc { '>>' } ]
   prompt2 = [ proc { '$' }, proc { '>' } ]
   pry = Pry.new :prompt => prompt1
   pry.push_prompt(prompt2)
   pry.pop_prompt # => prompt2
   pry.pop_prompt # => prompt1
   pry.pop_prompt # => prompt1

If the given line is a valid command, process it in the context of the current `eval_string` and context. This method should not need to be invoked directly. @param [String] val The line to process. @param [String] eval_string The cumulative lines of input. @param [Binding] target The target of the Pry session. @return [Boolean] `true` if `val` is a command, `false` otherwise

The current prompt. This is the prompt at the top of the prompt stack.

@example

   self.prompt = Pry::SIMPLE_PROMPT
   self.prompt # => Pry::SIMPLE_PROMPT

@return [Array<Proc>] Current prompt.

Pushes the current prompt onto a stack that it can be restored from later. Use this if you wish to temporarily change the prompt. @param [Array<Proc>] new_prompt @return [Array<Proc>] new_prompt @example

   new_prompt = [ proc { '>' }, proc { '>>' } ]
   push_prompt(new_prompt) # => new_prompt

Perform a read. If no parameter is given, default to top-level (main). This is a multi-line read; so the read continues until a valid Ruby expression is received. Pry commands are also accepted here and operate on the target. @param [Object, Binding] target The receiver of the read. @param [String] eval_string Optionally Prime `eval_string` with a start value. @return [String] The Ruby expression. @example

  Pry.new.r(Object.new)

Raise an exception out of Pry.

See Kernel#raise for documentation of parameters. See rb_make_exception for the inbuilt implementation.

This is necessary so that the raise-up command can tell the difference between an exception the user has decided to raise, and a mistake in specifying that exception.

(i.e. raise-up RunThymeError.new should not be the same as

 raise-up NameError, "unititialized constant RunThymeError")

Perform a read-eval If no parameter is given, default to top-level (main). @param [Object, Binding] target The receiver of the read-eval-print @return [Object] The result of the eval or an `Exception` object in case of

  error. In the latter case, you can check whether the exception was raised
  or is just the result of the expression using #last_result_is_exception?

@example

  Pry.new.re(Object.new)

Returns the next line of input to be used by the pry instance. This method should not need to be invoked directly. @param [String] current_prompt The prompt to use for input. @return [String] The next line of input.

Refresh the Pry instance settings from the Pry class. Allows options to be specified to override settings from Pry class. @param [Hash] options The options to override Pry class settings

  for this instance.

Perform a read-eval-print. If no parameter is given, default to top-level (main). @param [Object, Binding] target The receiver of the read-eval-print @example

  Pry.new.rep(Object.new)

Start a read-eval-print-loop. If no parameter is given, default to top-level (main). @param [Object, Binding] target The receiver of the Pry session @return [Object] The target of the Pry session or an explictly given

  return value. If given return value is `nil` or no return value
  is specified then `target` will be returned.

@example

  Pry.new.repl(Object.new)

Clean-up after the repl session. @param [Binding] target The target binding for the session.

Initialize the repl session. @param [Binding] target The target binding for the session.

Read and process a line of input — check for ^D, determine which prompt to use, rewrite the indentation if `Pry.config.auto_indent` is enabled, and, if the line is a command, process it and alter the eval_string accordingly. This method should not need to be invoked directly.

@param [String] eval_string The cumulative lines of input. @param [Binding] target The target of the session. @return [String] The line received.

Run the specified command. @param [String] val The command (and its params) to execute. @param [String] eval_string The current input buffer. @param [Binding] target The binding to use.. @return [Pry::Command::VOID_VALUE] @example

  pry_instance.run_command("ls -m")

Returns the appropriate prompt to use. This method should not need to be invoked directly. @param [String] eval_string The current input buffer. @param [Binding] target The target Binding of the Pry session. @return [String] The prompt.

Set the last result of an eval. This method should not need to be invoked directly. @param [Object] result The result. @param [Binding] target The binding to set `_` on. @param [String] code The code that was run.

Whether the print proc should be invoked. Currently only invoked if the output is not suppressed OR the last result is an exception regardless of suppression. @return [Boolean] Whether the print proc should be invoked.

Output the result or pass to an exception handler (if result is an exception).

@return [Hash] The currently defined sticky locals.

Update Pry‘s internal state after evalling code. This method should not need to be invoked directly. @param [String] code The code we just eval‘d

[Validate]