Handle -m/-M correctly [Fixes #365]

This commit is contained in:
Conrad Irwin 2011-12-07 22:26:04 -08:00
parent fb2850cf9b
commit 91a249845e
2 changed files with 35 additions and 2 deletions

View File

@ -47,11 +47,14 @@ class Pry
# Add the derived :method_object option to a used Slop instance.
def process_method_object_options(args, opts)
opts[:instance] = opts['instance-methods'] if opts.present?(:methods)
# TODO: de-hack when we upgrade Slop: https://github.com/injekt/slop/pull/30
opts.options[:super].force_argument_value opts.options[:super].count if opts.present?(:super)
get_method_or_raise(args.empty? ? nil : args.join(" "), @method_target, opts.to_hash(true))
get_method_or_raise(args.empty? ? nil : args.join(" "), @method_target,
:super => opts[:super],
:instance => opts.present?(:'instance-methods') && !opts.present?(:'methods'),
:methods => opts.present?(:'methods') && !opts.present?(:'instance-methods')
)
end
end
end

View File

@ -316,6 +316,36 @@ describe "Pry::DefaultCommands::Introspection" do
str_output.string.should =~ /Mr flibble/
end
it "should find instance methods with -M" do
c = Class.new{ def moo; "ve over!"; end }
mock_pry(binding, "cd c","show-method -M moo").should =~ /ve over/
end
it "should not find instance methods with -m" do
c = Class.new{ def moo; "ve over!"; end }
mock_pry(binding, "cd c", "show-method -m moo").should =~ /could not be found/
end
it "should find normal methods with -m" do
c = Class.new{ def self.moo; "ve over!"; end }
mock_pry(binding, "cd c", "show-method -m moo").should =~ /ve over/
end
it "should not find normal methods with -M" do
c = Class.new{ def self.moo; "ve over!"; end }
mock_pry(binding, "cd c", "show-method -M moo").should =~ /could not be found/
end
it "should find normal methods with no -M or -m" do
c = Class.new{ def self.moo; "ve over!"; end }
mock_pry(binding, "cd c", "show-method moo").should =~ /ve over/
end
it "should find instance methods with no -M or -m" do
c = Class.new{ def moo; "ve over!"; end }
mock_pry(binding, "cd c", "show-method moo").should =~ /ve over/
end
it "should find super methods" do
class Foo
def foo(*bars)