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.
VOID_VALUE | = | Object.new | represents a void return value for a command |
command_options | -> | options |
backward compatibility | ||
command_options= | -> | options= |
_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] |
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.
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})
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).
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.
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]