diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 033b85b9..197889ae 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -8,8 +8,18 @@ class Pry attr_accessor :module_object def module_object - name = args.first - @module_object ||= WrappedModule.from_str(name, target) + if @module_object + @module_object + else + name = args.first + @module_object = WrappedModule.from_str(name, target) + if @module_object + sup = @module_object.ancestors.select do |anc| + anc.class == @module_object.wrapped.class + end[opts[:super]] + @module_object = sup ? Pry::WrappedModule(sup) : nil + end + end end # @param [String] @@ -127,7 +137,7 @@ class Pry opt.on :f, :flood, "Do not use a pager to view text longer than one screen." 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) @@ -145,6 +155,7 @@ class Pry end def process_module + raise Pry::CommandError, "No documentation found." if module_object.nil? if opts.present?(:all) all_modules else @@ -274,6 +285,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 @@ -323,6 +335,7 @@ class Pry end def process_module + raise Pry::CommandError, "No documentation found." if module_object.nil? if opts.present?(:all) all_modules else diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index 73fd03c6..6d1437cf 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -17,7 +17,6 @@ class Pry include Pry::Helpers::DocumentationHelpers attr_reader :wrapped - private :wrapped # Convert a string to a module. # diff --git a/test/test_default_commands/test_show_source.rb b/test/test_default_commands/test_show_source.rb index 368bf495..b379239b 100644 --- a/test/test_default_commands/test_show_source.rb +++ b/test/test_default_commands/test_show_source.rb @@ -251,12 +251,23 @@ if !mri18_and_no_real_source_location? describe "on modules" do before do - class ShowSourceTestClass + class ShowSourceTestSuperClass + def alpha + end + end + + class ShowSourceTestClass