1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

* added new commands: help, status

* removed exit_at alias for jump_to, now only jump_to is valid
* updated documentation
* added another format for pry method, can now use 5.pry or pry(5)
This commit is contained in:
John Mair 2010-12-11 22:01:47 +13:00
parent 3ea896efba
commit 09685f360c
3 changed files with 50 additions and 14 deletions

View file

@ -8,7 +8,7 @@ _attach an irb-like session to any object at runtime_
Pry is a simple Ruby REPL (Read-Eval-Print-Loop) that specializes in the interactive
manipulation of objects during the running of a program.
It is not based on the IRB codebase and is small, at around 230 LOC.
It is not based on the IRB codebase and is small, at around 260 LOC.
* Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
* Read the [documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
@ -49,12 +49,18 @@ effect:
#### Alternative Syntax
You can also use the `obj.pry` syntax to start a pry session on
You can also use the `obj.pry` or `pry(obj)` syntax to start a pry session on
`obj`. e.g
5.pry
Beginning Pry session for 5
pry(5)>
OR
pry 6
beginning Pry session for 6
pry(6)>
example: Pry sessions can nest arbitrarily deep so we can pry on objects inside objects:
----------------------------------------------------------------------------------------
@ -97,7 +103,7 @@ command. E.g
=> nil
We can then jump back to any of the previous nesting levels by using
the `jump_to` or `exit_at` commands:
the `jump_to` command:
pry("friend":3)> jump_to 1
Ending Pry session for "friend"
@ -105,13 +111,13 @@ the `jump_to` or `exit_at` commands:
=> 100
pry(Hello):1>
If we just want to go back one level of nesting we can of course just
If we just want to go back one level of nesting we can of course
use the `quit` or `exit` or `back` commands.
To break out of all levels of Pry nesting and return immediately to the
calling process use `exit_all`:
pry("friend":3) exit_all
pry("friend":3)> exit_all
Ending Pry session for "friend"
Ending Pry session for 100
Ending Pry session for Hello
@ -139,7 +145,7 @@ Features:
* Pry has multi-line support built in.
* Pry gives good control over nested sessions (important when exploring complicated runtime state)
* Pry is not based on the IRB codebase.
* Pry is small; around 230 LOC.
* Pry is small; around 260 LOC.
* Pry implements all the methods in the REPL chain separately: `Pry.r`
for reading; `Pry.re` for eval; `Pry.rep` for printing; and `Pry.repl`
for the loop (`Pry.start` is simply an alias for `Pry.repl`). You can
@ -169,7 +175,7 @@ oneanother. They all start a Read-Eval-Print-Loop on the object they
receive as a parameter. In the case of no parameter they operate on
top-level (main). They can receive any object or a `Binding`
object as parameter.
* `obj.pry` may also be used as an alternate syntax to `Pry.start(obj)`
* `obj.pry` and `pry(obj)` may also be used as alternative syntax to `Pry.start(obj)`
* If, for some reason you do not want to 'loop' then use `Pry.rep()`; it
only performs the Read-Eval-Print section of the REPL - it ends the
session after just one line of input. It takes the same parameters as
@ -191,14 +197,15 @@ If you want to access a method of the same name, prefix the invocation by whites
* Typing `!` on a line by itself will refresh the REPL - useful for
getting you out of a situation if the parsing process
goes wrong.
* `status` shows status information about the current session.
* `help` shows the list of session commands with brief explanations.
* `exit` or `quit` or `back` will end the current Pry session and go
back to the calling process or back one level of nesting (if there
are nested sessions).
* `exit_program` or `quit_program` will end the currently running
program.
* `nesting` shows Pry nesting information.
* `jump_to <nest_level>` or `exit_at <nest_level>` unwinds the Pry
stack (nesting level) until the appropriate nesting level is reached
* `jump_to <nest_level>` unwinds the Pry stack (nesting level) until the appropriate nesting level is reached
-- as per the output of `nesting`
* `exit_all` breaks out of all Pry nesting levels and returns to the
calling process.

View file

@ -117,17 +117,23 @@ module Pry
when "!"
output.refresh
eval_string.clear
when "help"
output.show_help
eval_string.clear
when "nesting"
output.show_nesting(nesting)
eval_string.clear
when "status"
output.show_status(nesting, target)
eval_string.clear
when "exit_all"
throw(:breakout, 0)
when "exit", "quit", "back"
output.exit
throw(:breakout, nesting.level)
when /exit_at\s*(\d*)/, /jump_to\s*(\d*)/
when /jump_to\s*(\d*)/
nesting_level_breakout = ($~.captures).first.to_i
output.exit_at(nesting_level_breakout)
output.jump_to(nesting_level_breakout)
if nesting_level_breakout < 0 || nesting_level_breakout >= nesting.level
output.error_invalid_nest_level(nesting_level_breakout, nesting.level - 1)
@ -169,8 +175,8 @@ module Pry
end
module ObjectExtensions
def pry
Pry.start(Pry.binding_for(self))
def pry(target=self)
Pry.start(Pry.binding_for(target))
end
end
end

View file

@ -22,8 +22,22 @@ module Pry
end
end
def show_help
puts "Command list:"
puts "--"
puts "help This menu"
puts "status Show status information"
puts "! Refresh the REPL"
puts "nesting Show nesting information"
puts "exit/quit/back End the current Pry session"
puts "exit_all End all nested Pry sessions"
puts "exit_program/quit_program End the current program"
puts "jump_to <level> Jump to a Pry session further up the stack, exiting all sessions below"
end
def show_nesting(nesting)
puts "Nesting status:"
puts "--"
nesting.each do |level, obj|
if level == 0
puts "#{level}. #{obj.inspect} (Pry top level)"
@ -33,12 +47,21 @@ module Pry
end
end
def show_status(nesting, target)
puts "Status:"
puts "--"
puts "Receiver: #{target.eval('self').inspect}"
puts "Nesting level: #{nesting.level}"
puts "Local variables: #{target.eval("local_variables").inspect}"
puts "Last result: #{Pry.last_result.inspect}"
end
def error_invalid_nest_level(nest_level, max_nest_level)
puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{nest_level}."
end
def exit() end
def exit_at(nesting_level_breakout) end
def jump_to(nesting_level_breakout) end
def exit_program() end
end
end