From d2009e6de100b983db71eead36c24e17dfbb9c63 Mon Sep 17 00:00:00 2001 From: John Mair Date: Sun, 19 Dec 2010 00:21:58 +1300 Subject: [PATCH] version bump 0.3.0, added method_doc and friends, added cat, updated README, adjusted Rakefile to use 0.2.0 method_source gem --- README.markdown | 8 ++++++-- Rakefile | 2 +- lib/pry.rb | 26 ++++++++++++++++++-------- lib/pry/output.rb | 13 ++++++++++++- lib/pry/version.rb | 2 +- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/README.markdown b/README.markdown index 48713768..c21b2609 100644 --- a/README.markdown +++ b/README.markdown @@ -144,8 +144,8 @@ end. * Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back' * Use `_` to recover last result. * Pry has multi-line support built in. -* Pry has unique commands not found in any other REPL: `show_method`, -`jump_to`, `ls`, `cd` +* Pry has unique commands not found in any other REPL: `show_method`, `method_doc` +`jump_to`, `ls`, `cd`, `cat` * Pry gives good control over nested sessions (important when exploring complicated runtime state) * Pry is not based on the IRB codebase. * 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). * `ls` returns a list of local variables and instance variables in the current scope +* `cat ` calls `inspect` on `` * `cd ` starts a `Pry` session on the variable . E.g `cd @x` * `show_method ` Displays the sourcecode for the method . E.g `show_method hello` * `show_instance_method ` Displays the sourcecode for the instance method . E.g `show_instance_method goodbye` +* `method_doc ` Displays comments for `` +* `instance_method_doc ` Displays comments for instance + method `` * `exit_program` or `quit_program` will end the currently running program. * `nesting` shows Pry nesting information. diff --git a/Rakefile b/Rakefile index 73c2d373..388234af 100644 --- a/Rakefile +++ b/Rakefile @@ -20,7 +20,7 @@ def apply_spec_defaults(s) s.description = s.summary s.require_path = 'lib' 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.has_rdoc = 'yard' s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb", diff --git a/lib/pry.rb b/lib/pry.rb index 2e608a83..72355f89 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -3,8 +3,7 @@ direc = File.dirname(__FILE__) -require 'ruby_parser' -require 'method_source' +require "method_source" require "#{direc}/pry/version" require "#{direc}/pry/input" require "#{direc}/pry/output" @@ -158,18 +157,32 @@ class Pry when "ls" output.ls(target) eval_string.clear + when /^cat\s+(.+)/ + var = $~.captures.first + output.cat(target, var) + eval_string.clear when /^cd\s+(.+)/ obj = $~.captures.first target.eval("#{obj}.pry") 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*(.+)/ meth_name = ($~.captures).first - code = get_method_source(target, meth_name, :method) + code = target.eval("method(:#{meth_name})").source output.show_method code eval_string.clear when /^show_instance_method\s*(.+)/ 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 eval_string.clear when /^jump_to\s*(\d*)/ @@ -190,10 +203,6 @@ class Pry end end - def get_method_source(target, meth_name, kind) - target.eval("#{kind}(:#{meth_name}).source") - end - def prompt(eval_string, target, nest) target_self = target.eval('self') @@ -212,6 +221,7 @@ class Pry end else + require 'ruby_parser' def valid_expression?(code) RubyParser.new.parse(code) diff --git a/lib/pry/output.rb b/lib/pry/output.rb index c56470b7..2c416c88 100644 --- a/lib/pry/output.rb +++ b/lib/pry/output.rb @@ -30,9 +30,12 @@ class Pry puts "! Refresh the REPL" puts "nesting Show nesting information" puts "ls Show the list of variables in the current scope" + puts "cat Show output of .inspect" puts "cd Start a Pry session on (use `cd ..` to go back)" - puts "show_method Show the sourcecode for the method " + puts "show_method Show the sourcecode for the method " puts "show_instance_method Show the sourcecode for the instance method " + puts "method_doc Show the comments above " + puts "instance_method_doc Show the comments above instance method " 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" @@ -63,11 +66,19 @@ class Pry def ls(target) puts "#{target.eval('Pry.view(local_variables + instance_variables)')}" end + + def cat(target, var) + puts target.eval("#{var}.inspect") + end def show_method(code) code.display end + def show_doc(doc) + doc.display + end + def warn_already_at_level(nesting_level) puts "Already at nesting level #{nesting_level}" end diff --git a/lib/pry/version.rb b/lib/pry/version.rb index 4b795233..9c75e02e 100644 --- a/lib/pry/version.rb +++ b/lib/pry/version.rb @@ -1,3 +1,3 @@ class Pry - VERSION = "0.2.8" + VERSION = "0.3.0" end