Handle -m/-M correctly [Fixes #365]
This commit is contained in:
parent
fb2850cf9b
commit
91a249845e
|
@ -47,11 +47,14 @@ class Pry
|
||||||
|
|
||||||
# Add the derived :method_object option to a used Slop instance.
|
# Add the derived :method_object option to a used Slop instance.
|
||||||
def process_method_object_options(args, opts)
|
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
|
# 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)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -316,6 +316,36 @@ describe "Pry::DefaultCommands::Introspection" do
|
||||||
str_output.string.should =~ /Mr flibble/
|
str_output.string.should =~ /Mr flibble/
|
||||||
end
|
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
|
it "should find super methods" do
|
||||||
class Foo
|
class Foo
|
||||||
def foo(*bars)
|
def foo(*bars)
|
||||||
|
|
Loading…
Reference in New Issue