diff --git a/lib/pry/default_commands/documentation.rb b/lib/pry/default_commands/documentation.rb index 43e249d9..95c677fd 100644 --- a/lib/pry/default_commands/documentation.rb +++ b/lib/pry/default_commands/documentation.rb @@ -30,15 +30,6 @@ e.g show-doc hello_method next if opts.help? meth_name = args.shift - if meth_name - if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/ && !opts.context? - context, meth_name = $1, $2 - target = Pry.binding_for(target.eval(context)) - end - else - meth_name = meth_name_from_binding(target) - end - 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 @@ -48,11 +39,8 @@ e.g show-doc hello_method 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) - render_output(opts.flood?, false, doc) doc end @@ -82,15 +70,6 @@ e.g: stat hello_method next if opts.help? meth_name = args.shift - if meth_name - if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/ && !opts.context? - context, meth_name = $1, $2 - target = Pry.binding_for(target.eval(context)) - end - else - meth_name = meth_name_from_binding(target) - end - if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil? output.puts "Invalid method name: #{meth_name}. Type `stat --help` for help" next @@ -139,15 +118,6 @@ e.g: gist -d my_method # This needs to be extracted into its own method as it's shared # by show-method and show-doc and stat commands meth_name = args.shift - if meth_name - if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/ - context, meth_name = $1, $2 - target = Pry.binding_for(target.eval(context)) - end - else - meth_name = meth_name_from_binding(target) - end - if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil? output.puts "Invalid method name: #{meth_name}. Type `gist-method --help` for help" next @@ -169,7 +139,6 @@ e.g: gist -d my_method end end - end end diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 9b675cba..61966a14 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -27,15 +27,6 @@ e.g: show-method hello_method next if opts.help? meth_name = args.shift - if meth_name - if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/ && !opts.context? - context, meth_name = $1, $2 - target = Pry.binding_for(target.eval(context)) - end - else - meth_name = meth_name_from_binding(target) - end - 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 @@ -141,15 +132,6 @@ e.g: edit-method hello_method next if opts.help? meth_name = args.shift - if meth_name - if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/ && !opts.context? - context, meth_name = $1, $2 - target = Pry.binding_for(target.eval(context)) - end - else - meth_name = meth_name_from_binding(target) - end - if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil? output.puts "Invalid method name: #{meth_name}." next diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index 545c439e..3f397ba2 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -134,23 +134,35 @@ class Pry end def get_method_object(meth_name, target, options) + if meth_name + if meth_name =~ /(\S+)\#(\S+)\Z/ + context, meth_name = $1, $2 + target = Pry.binding_for(target.eval(context)) + options["instance-methods"] = true + options[:methods] = false + elsif meth_name =~ /(\S+)\.(\S+)\Z/ + context, meth_name = $1, $2 + target = Pry.binding_for(target.eval(context)) + options["instance-methods"] = false + options[:methods] = true + end + else + meth_name = meth_name_from_binding(target) + end + if !meth_name return nil end if options["instance-methods"] - target.eval("instance_method(:#{meth_name})") + target.eval("instance_method(:#{meth_name})") rescue nil elsif options[:methods] - target.eval("method(:#{meth_name})") + target.eval("method(:#{meth_name})") rescue nil else begin target.eval("instance_method(:#{meth_name})") rescue - begin - target.eval("method(:#{meth_name})") - rescue - return nil - end + target.eval("method(:#{meth_name})") rescue nil end end end