diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-05-12 09:07:57 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-05-12 09:07:57 +0000 |
commit | 9da4f78db46764be6dae5e7e83ff48cbecb3fb23 (patch) | |
tree | c0805e6c95d6396e28e6129d88905c4dee085f4e /lib/irb/completion.rb | |
parent | 014f2164ed7031a1c31604b290d2ab0cf1deacdc (diff) |
2000-05-12
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/irb/completion.rb')
-rw-r--r-- | lib/irb/completion.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb new file mode 100644 index 0000000000..cbd4012773 --- /dev/null +++ b/lib/irb/completion.rb @@ -0,0 +1,47 @@ + +require "readline" + +module IRB + module InputCompletion + ReservedWords = [ + "BEGIN", "END", + "alias", "and", + "begin", "break", + "case", "class", + "def", "defined", "do", + "else", "elsif", "end", "ensure", + "false", "for", + "if", "in", + "module", + "next", "nil", "not", + "or", + "redo", "rescue", "retry", "return", + "self", "super", + "then", "true", + "undef", "unless", "until", + "when", "while", + "yield" + ] + + CompletionProc = proc { |input| + case input + when /^([^.]+)\.([^.]*)$/ + receiver = $1 + message = $2 + if eval("(local_variables|#{receiver}.type.constants).include?('#{receiver}')", + IRB.conf[:MAIN_CONTEXT].bind) + candidates = eval("#{receiver}.methods", IRB.conf[:MAIN_CONTEXT].bind) + else + candidates = [] + end + candidates.grep(/^#{Regexp.quote(message)}/).collect{|e| receiver + "." + e} + else + candidates = eval("methods | private_methods | local_variables | type.constants", + IRB.conf[:MAIN_CONTEXT].bind) + (candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/) + end + } + end +end + +Readline.completion_proc = IRB::InputCompletion::CompletionProc |