DEFAULT_HOOKS | = | Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_| # ensure we're actually in a method file = target.eval('__FILE__') | The default hooks - display messages when beginning and ending Pry sessions. | |
Commands | = | Pry::CommandSet.new do import DefaultCommands::Basic | 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", "./.pryrc"] | The RC Files to load. | |
VERSION | = | "0.9.8.2" |
active_sessions | [RW] | @return [Fixnum] The number of active Pry sessions. |
backtrace | [RW] | |
binding_stack | [RW] | |
cli | [RW] | @return [Boolean] Whether Pry was activated from the command line. |
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] | |
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] | |
[RW] |
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.
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
@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 rc files given in the `Pry::RC_FILES` array. This method can also be used to reload the files if they have changed.
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‘
component of the REPL. (see print.rb)
Run a Pry command from outside a session. The commands available are those referenced by `Pry.commands` (the default command set). @param [String] arg_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
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`.
Determine if a string of code is a complete Ruby expression. @param [String] code The code to validate. @return [Boolean] Whether or not the code is a complete Ruby expression. @raise [SyntaxError] Any SyntaxError that does not represent incompleteness. @example
complete_expression?("class Hello") #=> false complete_expression?("class Hello; end") #=> true
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!
Check whether the exception indicates that the user should input more.
@param [SyntaxError] the exception object that was raised. @param [Array<String>] The stack frame of the function that executed eval. @return [Boolean]
@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
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)
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.
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")
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.
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