version bump 0.3.0, added method_doc and friends, added cat, updated README, adjusted Rakefile to use 0.2.0 method_source gem
This commit is contained in:
parent
6491b0454f
commit
d2009e6de1
|
@ -144,8 +144,8 @@ end.
|
||||||
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
|
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
|
||||||
* Use `_` to recover last result.
|
* Use `_` to recover last result.
|
||||||
* Pry has multi-line support built in.
|
* Pry has multi-line support built in.
|
||||||
* Pry has unique commands not found in any other REPL: `show_method`,
|
* Pry has unique commands not found in any other REPL: `show_method`, `method_doc`
|
||||||
`jump_to`, `ls`, `cd`
|
`jump_to`, `ls`, `cd`, `cat`
|
||||||
* Pry gives good control over nested sessions (important when exploring complicated runtime state)
|
* Pry gives good control over nested sessions (important when exploring complicated runtime state)
|
||||||
* Pry is not based on the IRB codebase.
|
* Pry is not based on the IRB codebase.
|
||||||
* Pry uses [RubyParser](https://github.com/seattlerb/ruby_parser) to
|
* Pry uses [RubyParser](https://github.com/seattlerb/ruby_parser) to
|
||||||
|
@ -202,11 +202,15 @@ If you want to access a method of the same name, prefix the invocation by whites
|
||||||
are nested sessions).
|
are nested sessions).
|
||||||
* `ls` returns a list of local variables and instance variables in the
|
* `ls` returns a list of local variables and instance variables in the
|
||||||
current scope
|
current scope
|
||||||
|
* `cat <var>` calls `inspect` on `<var>`
|
||||||
* `cd <var>` starts a `Pry` session on the variable <var>. E.g `cd @x`
|
* `cd <var>` starts a `Pry` session on the variable <var>. E.g `cd @x`
|
||||||
* `show_method <methname>` Displays the sourcecode for the method
|
* `show_method <methname>` Displays the sourcecode for the method
|
||||||
<methname>. E.g `show_method hello`
|
<methname>. E.g `show_method hello`
|
||||||
* `show_instance_method <methname>` Displays the sourcecode for the
|
* `show_instance_method <methname>` Displays the sourcecode for the
|
||||||
instance method <methname>. E.g `show_instance_method goodbye`
|
instance method <methname>. E.g `show_instance_method goodbye`
|
||||||
|
* `method_doc <methname>` Displays comments for `<methname>`
|
||||||
|
* `instance_method_doc <methname>` Displays comments for instance
|
||||||
|
method `<methname>`
|
||||||
* `exit_program` or `quit_program` will end the currently running
|
* `exit_program` or `quit_program` will end the currently running
|
||||||
program.
|
program.
|
||||||
* `nesting` shows Pry nesting information.
|
* `nesting` shows Pry nesting information.
|
||||||
|
|
2
Rakefile
2
Rakefile
|
@ -20,7 +20,7 @@ def apply_spec_defaults(s)
|
||||||
s.description = s.summary
|
s.description = s.summary
|
||||||
s.require_path = 'lib'
|
s.require_path = 'lib'
|
||||||
s.add_dependency("ruby_parser",">=2.0.5")
|
s.add_dependency("ruby_parser",">=2.0.5")
|
||||||
s.add_dependency("method_source",">=0.1.4")
|
s.add_dependency("method_source",">=0.2.0")
|
||||||
s.homepage = "http://banisterfiend.wordpress.com"
|
s.homepage = "http://banisterfiend.wordpress.com"
|
||||||
s.has_rdoc = 'yard'
|
s.has_rdoc = 'yard'
|
||||||
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
|
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
|
||||||
|
|
26
lib/pry.rb
26
lib/pry.rb
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
direc = File.dirname(__FILE__)
|
direc = File.dirname(__FILE__)
|
||||||
|
|
||||||
require 'ruby_parser'
|
require "method_source"
|
||||||
require 'method_source'
|
|
||||||
require "#{direc}/pry/version"
|
require "#{direc}/pry/version"
|
||||||
require "#{direc}/pry/input"
|
require "#{direc}/pry/input"
|
||||||
require "#{direc}/pry/output"
|
require "#{direc}/pry/output"
|
||||||
|
@ -158,18 +157,32 @@ class Pry
|
||||||
when "ls"
|
when "ls"
|
||||||
output.ls(target)
|
output.ls(target)
|
||||||
eval_string.clear
|
eval_string.clear
|
||||||
|
when /^cat\s+(.+)/
|
||||||
|
var = $~.captures.first
|
||||||
|
output.cat(target, var)
|
||||||
|
eval_string.clear
|
||||||
when /^cd\s+(.+)/
|
when /^cd\s+(.+)/
|
||||||
obj = $~.captures.first
|
obj = $~.captures.first
|
||||||
target.eval("#{obj}.pry")
|
target.eval("#{obj}.pry")
|
||||||
eval_string.clear
|
eval_string.clear
|
||||||
|
when /^method_doc\s*(.+)/
|
||||||
|
meth_name = ($~.captures).first
|
||||||
|
doc = target.eval("method(:#{meth_name})").comment
|
||||||
|
output.show_doc doc
|
||||||
|
eval_string.clear
|
||||||
|
when /^instance_method_doc\s*(.+)/
|
||||||
|
meth_name = ($~.captures).first
|
||||||
|
doc = target.eval("instance_method(:#{meth_name})").comment
|
||||||
|
output.show_doc doc
|
||||||
|
eval_string.clear
|
||||||
when /^show_method\s*(.+)/
|
when /^show_method\s*(.+)/
|
||||||
meth_name = ($~.captures).first
|
meth_name = ($~.captures).first
|
||||||
code = get_method_source(target, meth_name, :method)
|
code = target.eval("method(:#{meth_name})").source
|
||||||
output.show_method code
|
output.show_method code
|
||||||
eval_string.clear
|
eval_string.clear
|
||||||
when /^show_instance_method\s*(.+)/
|
when /^show_instance_method\s*(.+)/
|
||||||
meth_name = ($~.captures).first
|
meth_name = ($~.captures).first
|
||||||
code = get_method_source(target, meth_name, :instance_method)
|
code = target.eval("instance_method(:#{meth_name})").source
|
||||||
output.show_method code
|
output.show_method code
|
||||||
eval_string.clear
|
eval_string.clear
|
||||||
when /^jump_to\s*(\d*)/
|
when /^jump_to\s*(\d*)/
|
||||||
|
@ -190,10 +203,6 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_method_source(target, meth_name, kind)
|
|
||||||
target.eval("#{kind}(:#{meth_name}).source")
|
|
||||||
end
|
|
||||||
|
|
||||||
def prompt(eval_string, target, nest)
|
def prompt(eval_string, target, nest)
|
||||||
target_self = target.eval('self')
|
target_self = target.eval('self')
|
||||||
|
|
||||||
|
@ -212,6 +221,7 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
require 'ruby_parser'
|
||||||
|
|
||||||
def valid_expression?(code)
|
def valid_expression?(code)
|
||||||
RubyParser.new.parse(code)
|
RubyParser.new.parse(code)
|
||||||
|
|
|
@ -30,9 +30,12 @@ class Pry
|
||||||
puts "! Refresh the REPL"
|
puts "! Refresh the REPL"
|
||||||
puts "nesting Show nesting information"
|
puts "nesting Show nesting information"
|
||||||
puts "ls Show the list of variables in the current scope"
|
puts "ls Show the list of variables in the current scope"
|
||||||
|
puts "cat <var> Show output of <var>.inspect"
|
||||||
puts "cd <var> Start a Pry session on <var> (use `cd ..` to go back)"
|
puts "cd <var> Start a Pry session on <var> (use `cd ..` to go back)"
|
||||||
puts "show_method <methname> Show the sourcecode for the method <method_name>"
|
puts "show_method <methname> Show the sourcecode for the method <methname>"
|
||||||
puts "show_instance_method <methname> Show the sourcecode for the instance method <method_name>"
|
puts "show_instance_method <methname> Show the sourcecode for the instance method <method_name>"
|
||||||
|
puts "method_doc <methname> Show the comments above <methname>"
|
||||||
|
puts "instance_method_doc <methname> Show the comments above instance method <methname>"
|
||||||
puts "exit/quit/back End the current Pry session"
|
puts "exit/quit/back End the current Pry session"
|
||||||
puts "exit_all End all nested Pry sessions"
|
puts "exit_all End all nested Pry sessions"
|
||||||
puts "exit_program/quit_program End the current program"
|
puts "exit_program/quit_program End the current program"
|
||||||
|
@ -63,11 +66,19 @@ class Pry
|
||||||
def ls(target)
|
def ls(target)
|
||||||
puts "#{target.eval('Pry.view(local_variables + instance_variables)')}"
|
puts "#{target.eval('Pry.view(local_variables + instance_variables)')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cat(target, var)
|
||||||
|
puts target.eval("#{var}.inspect")
|
||||||
|
end
|
||||||
|
|
||||||
def show_method(code)
|
def show_method(code)
|
||||||
code.display
|
code.display
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show_doc(doc)
|
||||||
|
doc.display
|
||||||
|
end
|
||||||
|
|
||||||
def warn_already_at_level(nesting_level)
|
def warn_already_at_level(nesting_level)
|
||||||
puts "Already at nesting level #{nesting_level}"
|
puts "Already at nesting level #{nesting_level}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
class Pry
|
class Pry
|
||||||
VERSION = "0.2.8"
|
VERSION = "0.3.0"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue