ruby-changes:18569
From: keiju <ko1@a...>
Date: Tue, 18 Jan 2011 18:34:17 +0900 (JST)
Subject: [ruby-changes:18569] Ruby:r30592 (trunk): * lib/irb/comletion.rb: Irb tab completion support for XX::method forms.
keiju 2011-01-18 18:34:10 +0900 (Tue, 18 Jan 2011) New Revision: 30592 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30592 Log: * lib/irb/comletion.rb: Irb tab completion support for XX::method forms. Modified files: trunk/ChangeLog trunk/lib/irb/completion.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 30591) +++ ChangeLog (revision 30592) @@ -1,3 +1,7 @@ +Tue Jan 18 18:31:14 2011 Keiju Ishitsuka <keiju@i...> + + * lib/irb/comletion.rb: Irb tab completion support for XX::method forms. + Tue Jan 18 15:05:55 2011 NAKAMURA, Hiroshi <nahi@r...> * lib/logger.rb: added RDoc document for logging message escape Index: lib/irb/completion.rb =================================================================== --- lib/irb/completion.rb (revision 30591) +++ lib/irb/completion.rb (revision 30592) @@ -91,60 +91,73 @@ rescue Exception candidates = [] end - candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e} + select_message(receiver, message, candidates, "::") - when /^(:[^:.]+)\.([^.]*)$/ + when /^(:[^:.]+)(\.|::)([^.]*)$/ # Symbol receiver = $1 - message = Regexp.quote($2) + sep = $2 + message = Regexp.quote($3) candidates = Symbol.instance_methods.collect{|m| m.to_s} - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) - when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/ + when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)(\.|::)([^.]*)$/ # Numeric receiver = $1 - message = Regexp.quote($5) + sep = $5 + message = Regexp.quote($6) begin candidates = eval(receiver, bind).methods.collect{|m| m.to_s} rescue Exception candidates = [] end - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) - when /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/ + when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/ # Numeric(0xFFFF) receiver = $1 - message = Regexp.quote($2) + sep = $2 + message = Regexp.quote($3) begin candidates = eval(receiver, bind).methods.collect{|m| m.to_s} rescue Exception candidates = [] end - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) when /^(\$[^.]*)$/ + # global var regmessage = Regexp.new(Regexp.quote($1)) candidates = global_variables.collect{|m| m.to_s}.grep(regmessage) # when /^(\$?(\.?[^.]+)+)\.([^.]*)$/ # when /^((\.?[^.]+)+)\.([^.]*)$/ - when /^([^."].*)\.([^.]*)$/ - # variable +# when /^([^."].*)\.([^.]*)$/ + when /^([^."].*)(\.|::)([^.]*)$/ + # variable.func or func.func receiver = $1 - message = Regexp.quote($2) + sep = $2 + message = Regexp.quote($3) gv = eval("global_variables", bind).collect{|m| m.to_s} lv = eval("local_variables", bind).collect{|m| m.to_s} cv = eval("self.class.constants", bind).collect{|m| m.to_s} if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver - # foo.func and foo is local var. OR + # foo.func and foo is var. OR + # foo::func and foo is var. OR + # foo::Const and foo is var. OR # Foo::Bar.func begin - candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s} + candidates = [] + rec = eval(receiver, bind) + if sep == "::" and rec.kind_of?(Module) + candidates = rec.constants.collect{|m| m.to_s} + end + candidates |= rec.methods.collect{|m| m.to_s} rescue Exception candidates = [] end @@ -164,7 +177,7 @@ candidates.sort! candidates.uniq! end - select_message(receiver, message, candidates) + select_message(receiver, message, candidates, sep) when /^\.([^.]*)$/ # unknown(maybe String) @@ -186,11 +199,11 @@ "<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>", "[]", "[]=", "^", "!", "!=", "!~"] - def self.select_message(receiver, message, candidates) + def self.select_message(receiver, message, candidates, sep = ".") candidates.grep(/^#{message}/).collect do |e| case e when /^[a-zA-Z_]/ - receiver + "." + e + receiver + sep + e when /^[0-9]/ when *Operators #receiver + " " + e -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/