Class Pry::Command
In: lib/pry/command.rb
Parent: Object

The super-class of all commands, new commands should be created by calling {Pry::CommandSet#command} which creates a BlockCommand or {Pry::CommandSet#create_command} which creates a ClassCommand. Please don‘t use this class directly.

Methods

Included Modules

Pry::Helpers::BaseHelpers Pry::Helpers::CommandHelpers

Classes and Modules

Module Pry::Command::VOID_VALUE
Class Pry::Command::AmendLine
Class Pry::Command::Bang
Class Pry::Command::BangPry
Class Pry::Command::Cat
Class Pry::Command::Cd
Class Pry::Command::ChangeInspector
Class Pry::Command::ChangePrompt
Class Pry::Command::CodeCollector
Class Pry::Command::DisablePry
Class Pry::Command::Edit
Class Pry::Command::Exit
Class Pry::Command::ExitAll
Class Pry::Command::ExitProgram
Class Pry::Command::FindMethod
Class Pry::Command::FixIndent
Class Pry::Command::GemCd
Class Pry::Command::GemInstall
Class Pry::Command::GemList
Class Pry::Command::GemOpen
Class Pry::Command::Gist
Class Pry::Command::Help
Class Pry::Command::Hist
Class Pry::Command::ImportSet
Class Pry::Command::InstallCommand
Class Pry::Command::JumpTo
Class Pry::Command::ListInspectors
Class Pry::Command::ListPrompts
Class Pry::Command::Ls
Class Pry::Command::Nesting
Class Pry::Command::Play
Class Pry::Command::PryBacktrace
Class Pry::Command::RaiseUp
Class Pry::Command::ReloadCode
Class Pry::Command::Reset
Class Pry::Command::Ri
Class Pry::Command::SaveFile
Class Pry::Command::ShellCommand
Class Pry::Command::ShellMode
Class Pry::Command::ShowDoc
Class Pry::Command::ShowInfo
Class Pry::Command::ShowInput
Class Pry::Command::ShowSource
Class Pry::Command::SimplePrompt
Class Pry::Command::Stat
Class Pry::Command::SwitchTo
Class Pry::Command::ToggleColor
Class Pry::Command::Version
Class Pry::Command::WatchExpression
Class Pry::Command::Whereami
Class Pry::Command::Wtf

Constants

VOID_VALUE = Object.new   represents a void return value for a command

External Aliases

command_options -> options
  backward compatibility
command_options= -> options=
source_file -> file
source_line -> line

Attributes

_pry_  [RW] 
arg_string  [RW] 
block  [W] 
captures  [RW] 
command_block  [RW]  The block we pass into a command so long as `:takes_block` is not equal to `false` @example
  my-command | do
    puts "block content"
  end
command_options  [W] 
command_set  [RW] 
context  [RW] 
description  [W] 
eval_string  [RW] 
match  [W] 
output  [RW]  Properties of one execution of a command (passed by {Pry#run_command} as a hash of context and expanded in `initialize`
target  [RW] 

Public Class methods

Define or get the command‘s banner

Define or get the command‘s options

Define or get the command‘s description

The group in which the command should be displayed in "help" output. This is usually auto-generated from directory naming, but it can be manually overridden if necessary. Group should not be changed once it is initialized.

Store hooks to be run before or after the command body. @see {Pry::CommandSet#before_command} @see {Pry::CommandSet#after_command}

How well does this command match the given line?

Higher scores are better because they imply that this command matches the line more closely.

The score is calculated by taking the number of characters at the start of the string that are used only to identify the command, not as part of the arguments.

@example

  /\.(.*)/.match_score(".foo") #=> 1
  /\.*(.*)/.match_score("...foo") #=> 3
  'hi'.match_score("hi there") #=> 2

@param [String] val A line input at the REPL @return [Fixnum]

Should this command be called for the given line? @param [String] val A line input at the REPL @return [Boolean]

Instantiate a command, in preparation for calling it. @param [Hash] context The runtime context to use with this command.

Create a new command with the given properties. @param [String, Regex] match The thing that triggers this command @param [String] description The description to appear in `help` @param [Hash] options Behavioral options (see {Pry::CommandSet#command}) @param [Module] helpers A module of helper functions to be included. @yield optional, used for BlockCommands @return [Class] (a subclass of {Pry::Command})

Public Instance methods

Run the command with the given `args`.

This is a public wrapper around `call` which ensures all preconditions are met.

@param [Array<String>] args The arguments to pass to this command. @return [Object] The return value of the `call` method, or

  {Command::VOID_VALUE}.

Display a warning if a command collides with a local/method in the current scope.

Generate completions for this command

@param [String] search The line typed so far @return [Array<String>] Completion words

Are all the gems required to use this command installed?

@return Boolean

Revaluate the string (str) and perform interpolation. @param [String] str The string to reevaluate with interpolation.

@return [String] The reevaluated string with interpolations

  applied (if any).

Make those properties accessible to instances

Process a line that Command.matches? this command. @param [String] line The line to process @return [Object, Command::VOID_VALUE]

Run a command from another command. @param [String] command_string The string that invokes the command @param [Array] args Further arguments to pass to the command @example

  run "show-input"

@example

  run ".ls"

@example

  run "amend-line",  "5", 'puts "hello world"'

@return [Hash] Pry commands can store arbitrary state

  here. This state persists between subsequent command invocations.
  All state saved here is unique to the command, it does not
  need to be namespaced.

@example

  state.my_state = "my state"  # this will not conflict with any
                               # `state.my_state` used in another command.

@return [Object] The value of `self` inside the `target` binding.

Extract necessary information from a line that Command.matches? this command.

Returns an array of four elements:

```

 [String] the portion of the line that matched with the Command match
 [String] a string of all the arguments (i.e. everything but the match)
 [Array]  the captures caught by the command_regex
 [Array]  the arguments obtained by splitting the arg_string

```

@param [String] val The line of input @return [Array]

[Validate]