From b2324727e19d72efaa9666864cd096d22cc4a733 Mon Sep 17 00:00:00 2001 From: aycabta Date: Sat, 4 Sep 2021 05:33:03 +0900 Subject: [PATCH] Retrieve completed receiver that is a module or class correctly --- lib/irb/completion.rb | 3 ++- test/irb/test_completion.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index c7c0fb99e..385957c3f 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -296,7 +296,8 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace candidates.uniq! end if doc_namespace - "#{rec.class.name}#{sep}#{candidates.find{ |i| i == message }}" + rec_class = rec.is_a?(Module) ? rec : rec.class + "#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}" else select_message(receiver, message, candidates, sep) end diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index 260b8a889..a661d68c5 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -89,5 +89,10 @@ def test_complete_variable assert_include(IRB::InputCompletor.retrieve_completion_data("str_examp", bind: binding), "str_example") assert_equal(IRB::InputCompletor.retrieve_completion_data("str_example", bind: binding, doc_namespace: true), "String") end + + def test_complete_class_method + assert_include(IRB::InputCompletor.retrieve_completion_data("String.new", bind: binding), "String.new") + assert_equal(IRB::InputCompletor.retrieve_completion_data("String.new", bind: binding, doc_namespace: true), "String.new") + end end end