[前][次][番号順一覧][スレッド一覧]

ruby-changes:64782

From: Nobuhiro <ko1@a...>
Date: Fri, 8 Jan 2021 13:38:34 +0900 (JST)
Subject: [ruby-changes:64782] f594775230 (master): [ruby/irb] do not escape a predicate method for doc namespace

https://git.ruby-lang.org/ruby.git/commit/?id=f594775230

From f59477523053b67eac409b6595bfe5db962aab3d Mon Sep 17 00:00:00 2001
From: Nobuhiro IMAI <nov@y...>
Date: Wed, 6 Jan 2021 19:05:46 +0900
Subject: [ruby/irb] do not escape a predicate method for doc namespace

* Fixes #88

https://github.com/ruby/irb/commit/d431a30af4

diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index 6d82139..22a1ad1 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -47,7 +47,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L47
       when /^((["'`]).*\2)\.([^.]*)$/
         # String
         receiver = $1
-        message = Regexp.quote($3)
+        message = $3
 
         candidates = String.instance_methods.collect{|m| m.to_s}
         if doc_namespace
@@ -59,7 +59,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L59
       when /^(\/[^\/]*\/)\.([^.]*)$/
         # Regexp
         receiver = $1
-        message = Regexp.quote($2)
+        message = $2
 
         candidates = Regexp.instance_methods.collect{|m| m.to_s}
         if doc_namespace
@@ -71,7 +71,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L71
       when /^([^\]]*\])\.([^.]*)$/
         # Array
         receiver = $1
-        message = Regexp.quote($2)
+        message = $2
 
         candidates = Array.instance_methods.collect{|m| m.to_s}
         if doc_namespace
@@ -83,7 +83,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L83
       when /^([^\}]*\})\.([^.]*)$/
         # Proc or Hash
         receiver = $1
-        message = Regexp.quote($2)
+        message = $2
 
         proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
         hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
@@ -117,7 +117,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L117
       when /^([A-Z].*)::([^:.]*)$/
         # Constant or class methods
         receiver = $1
-        message = Regexp.quote($2)
+        message = $2
         begin
           candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
           candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
@@ -134,7 +134,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L134
         # Symbol
         receiver = $1
         sep = $2
-        message = Regexp.quote($3)
+        message = $3
 
         candidates = Symbol.instance_methods.collect{|m| m.to_s}
         if doc_namespace
@@ -147,7 +147,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L147
         # Numeric
         receiver = $~[:num]
         sep = $~[:sep]
-        message = Regexp.quote($~[:mes])
+        message = $~[:mes]
 
         begin
           instance = eval(receiver, bind)
@@ -169,7 +169,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L169
         # Numeric(0xFFFF)
         receiver = $1
         sep = $2
-        message = Regexp.quote($3)
+        message = $3
 
         begin
           instance = eval(receiver, bind)
@@ -201,7 +201,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L201
         # variable.func or func.func
         receiver = $1
         sep = $2
-        message = Regexp.quote($3)
+        message = $3
 
         gv = eval("global_variables", bind).collect{|m| m.to_s}.push("true", "false", "nil")
         lv = eval("local_variables", bind).collect{|m| m.to_s}
@@ -244,7 +244,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L244
         # unknown(maybe String)
 
         receiver = ""
-        message = Regexp.quote($1)
+        message = $1
 
         candidates = String.instance_methods(true).collect{|m| m.to_s}
         if doc_namespace
@@ -294,7 +294,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L294
     Operators = %w[% & * ** + - / < << <= <=> == === =~ > >= >> [] []= ^ ! != !~]
 
     def self.select_message(receiver, message, candidates, sep = ".")
-      candidates.grep(/^#{message}/).collect do |e|
+      candidates.grep(/^#{Regexp.quote(message)}/).collect do |e|
         case e
         when /^[a-zA-Z_]/
           receiver + sep + e
diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb
index a765bbf..39d4be4 100644
--- a/test/irb/test_completion.rb
+++ b/test/irb/test_completion.rb
@@ -47,5 +47,13 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_completion.rb#L47
         assert_include candidates, word
       end
     end
+
+    def test_complete_predicate?
+      candidates = IRB::InputCompletor.retrieve_completion_data("1.posi", bind: binding)
+      assert_equal %w[1.positive?], candidates
+
+      namespace = IRB::InputCompletor.retrieve_completion_data("1.positive?", bind: binding, doc_namespace: true)
+      assert_equal "Integer.positive?", namespace
+    end
   end
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]