From 5bd86d410021cf59a9e4c3d9812fdb4f76ecde31 Mon Sep 17 00:00:00 2001 From: Trey Lawrence Date: Fri, 20 Jul 2012 15:45:03 -0400 Subject: [PATCH] Add super option for show-source command and add three tests --- lib/pry/default_commands/introspection.rb | 22 ++++-------- .../test_default_commands/test_show_source.rb | 34 ++++++++++++++++--- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 033b85b9..81f921bb 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -10,6 +10,11 @@ class Pry def module_object name = args.first @module_object ||= WrappedModule.from_str(name, target) + sup = @module_object + opts[:super].times do + sup = Pry::WrappedModule(sup.superclass) unless sup.superclass.nil? + end + sup end # @param [String] @@ -128,22 +133,6 @@ class Pry opt.on :a, :all, "Show docs for all definitions and monkeypatches of the module/class" end - def process_sourcable_object - name = args.first - object = target.eval(name) - - file_name, line = object.source_location - - doc = Pry::Code.from_file(file_name).comment_describing(line) - doc = strip_leading_hash_and_whitespace_from_ruby_comments(doc) - - result = "" - result << "\n#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{line}:\n" - result << "#{Pry::Helpers::Text.bold('Number of lines:')} #{doc.lines.count}\n\n" - result << doc - result << "\n" - end - def process_module if opts.present?(:all) all_modules @@ -274,6 +263,7 @@ class Pry e.g: `show-source Pry#rep` # source for Pry#rep method e.g: `show-source Pry` # source for Pry class e.g: `show-source Pry -a` # source for all Pry class definitions (all monkey patches) + e.g: `show-source Pry --super # source for superclass of Pry (Object class) https://github.com/pry/pry/wiki/Source-browsing#wiki-Show_method BANNER diff --git a/test/test_default_commands/test_show_source.rb b/test/test_default_commands/test_show_source.rb index 368bf495..6f2c9c57 100644 --- a/test/test_default_commands/test_show_source.rb +++ b/test/test_default_commands/test_show_source.rb @@ -237,7 +237,7 @@ if !mri18_and_no_real_source_location? it "source of variable should take precedence over method that is being shadowed" do string = mock_pry(@method_shadow,"show-source hello","exit-all") string.include?("def hello").should == false - string.should =~ /proc { ' smile ' }/ + string =~ /proc { ' smile ' }/ end it "source of method being shadowed should take precedence over variable @@ -251,7 +251,12 @@ if !mri18_and_no_real_source_location? describe "on modules" do before do - class ShowSourceTestClass + class ShowSourceTestSuperClass + def alpha + end + end + + class ShowSourceTestClass