diff options
author | Conrad Irwin <conrad.irwin@gmail.com> | 2012-11-08 01:18:15 -0800 |
---|---|---|
committer | Conrad Irwin <conrad.irwin@gmail.com> | 2012-11-08 01:24:53 -0800 |
commit | 7547b8ca16f4c981062957211b753127adaa565c (patch) | |
tree | 2d74a578b26d148e41ea68dbaa0d843972857c07 | |
parent | 5246700e2b074229c811cd0216c574bc8a46970e (diff) | |
download | pry-7547b8ca16f4c981062957211b753127adaa565c.tar.gz |
Completion for show-source/show-doc/?/$ Array#<tab>
-rw-r--r-- | lib/pry/command_set.rb | 6 | ||||
-rw-r--r-- | lib/pry/helpers/module_introspection_helpers.rb | 16 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 2a39d2e7..231b761c 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -234,6 +234,12 @@ class Pry run action, *args end + c.class_eval do + define_method(:complete) do |input| + cmd.new(context).complete(input) + end + end + c.group "Aliases" c diff --git a/lib/pry/helpers/module_introspection_helpers.rb b/lib/pry/helpers/module_introspection_helpers.rb index 75e04cb4..e57e4d76 100644 --- a/lib/pry/helpers/module_introspection_helpers.rb +++ b/lib/pry/helpers/module_introspection_helpers.rb @@ -127,6 +127,22 @@ class Pry retry end end + + def complete(input) + if input =~ /([^ ]*)#([a-z0-9_]*)\z/ + prefix, search = [$1, $2] + methods = begin + Pry::Method.all_from_class(binding.eval(prefix)) + rescue RescuableException => e + return super + end + methods.map do |method| + [prefix, method.name].join('#') if method.name.start_with?(search) + end.compact + else + super + end + end end end end |