diff --git a/lib/pry/default_commands/documentation.rb b/lib/pry/default_commands/documentation.rb index d11d8c92..3e5fe605 100644 --- a/lib/pry/default_commands/documentation.rb +++ b/lib/pry/default_commands/documentation.rb @@ -11,7 +11,7 @@ class Pry target = target() opts = Slop.parse!(args) do |opt| - opt.banner = "Usage: show-doc [OPTIONS] [METH]\n" \ + opt.banner = "Usage: show-doc [OPTIONS] [METH 1] [METH 2] [METH N]\n" \ "Show the comments above method METH. Tries instance methods first and then methods by default.\n" \ "e.g show-doc hello_method" @@ -28,25 +28,28 @@ class Pry next if opts.help? - meth_name = args.shift - if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil? - output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help" - next - end + args = [nil] if args.empty? + args.each do |method_name| + meth_name = method_name + if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil? + output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help" + next + end - doc, code_type = doc_and_code_type_for(meth) - next if !doc + doc, code_type = doc_and_code_type_for(meth) + next if !doc - next output.puts("No documentation found.") if doc.empty? - doc = process_comment_markup(doc, code_type) - output.puts make_header(meth, code_type, doc) - output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}" - if meth.respond_to?(:parameters) - output.puts "#{text.bold("signature: ")} #{signature_for(meth)}" - output.puts + next output.puts("No documentation found.") if doc.empty? + doc = process_comment_markup(doc, code_type) + output.puts make_header(meth, code_type, doc) + output.puts "#{text.bold("visibility: ")} #{method_visibility(meth).to_s}" + if meth.respond_to?(:parameters) + output.puts "#{text.bold("signature: ")} #{signature_for(meth)}" + output.puts + end + render_output(opts.flood?, false, doc) + doc end - render_output(opts.flood?, false, doc) - doc end alias_command "?", "show-doc", "" diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index ed248d12..6e8d168b 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -9,7 +9,7 @@ class Pry target = target() opts = Slop.parse!(args) do |opt| - opt.banner "Usage: show-method [OPTIONS] [METH]\n" \ + opt.banner "Usage: show-method [OPTIONS] [METH 1] [METH 2] [METH N]\n" \ "Show the source for method METH. Tries instance methods first and then methods by default.\n" \ "e.g: show-method hello_method" @@ -29,30 +29,33 @@ class Pry next if opts.help? - meth_name = args.shift - if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil? - output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help" - next + args = [nil] if args.empty? + args.each do |method_name| + meth_name = method_name + if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil? + output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help" + next + end + + code, code_type = code_and_code_type_for(meth) + next if !code + + output.puts make_header(meth, code_type, code) + if Pry.color + code = CodeRay.scan(code, code_type).term + end + + start_line = false + if opts.l? + start_line = meth.source_location ? meth.source_location.last : 1 + end + + start_line = opts.b? ? 1 : start_line + + + render_output(opts.flood?, start_line, code) + code end - - code, code_type = code_and_code_type_for(meth) - next if !code - - output.puts make_header(meth, code_type, code) - if Pry.color - code = CodeRay.scan(code, code_type).term - end - - start_line = false - if opts.l? - start_line = meth.source_location ? meth.source_location.last : 1 - end - - start_line = opts.b? ? 1 : start_line - - - render_output(opts.flood?, start_line, code) - code end alias_command "show-source", "show-method", "" diff --git a/test/helper.rb b/test/helper.rb index 9f00799a..26167365 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -32,6 +32,11 @@ def sample_method :sample end +# another sample doc +def another_sample_method + :another_sample +end + def redirect_pry_io(new_in, new_out) old_in = Pry.input old_out = Pry.output diff --git a/test/test_default_commands/test_documentation.rb b/test/test_default_commands/test_documentation.rb index 235c29b9..56e11d48 100644 --- a/test/test_default_commands/test_documentation.rb +++ b/test/test_default_commands/test_documentation.rb @@ -10,6 +10,16 @@ describe "Pry::DefaultCommands::Documentation" do str_output.string.should =~ /sample doc/ end + + it 'should output multiple methods\' documentation' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-doc sample_method another_sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /sample doc/ + str_output.string.should =~ /another sample doc/ + end it 'should output a method\'s documentation if inside method without needing to use method name' do $str_output = StringIO.new diff --git a/test/test_default_commands/test_introspection.rb b/test/test_default_commands/test_introspection.rb index a3580d3d..5e8bc84a 100644 --- a/test/test_default_commands/test_introspection.rb +++ b/test/test_default_commands/test_introspection.rb @@ -10,6 +10,16 @@ describe "Pry::DefaultCommands::Introspection" do str_output.string.should =~ /def sample/ end + + it 'should output multiple methods\' sources' do + str_output = StringIO.new + redirect_pry_io(InputTester.new("show-method sample_method another_sample_method", "exit-all"), str_output) do + pry + end + + str_output.string.should =~ /def sample/ + str_output.string.should =~ /def another_sample/ + end it 'should output a method\'s source with line numbers' do str_output = StringIO.new