ruby-changes:67557
From: aycabta <ko1@a...>
Date: Thu, 2 Sep 2021 21:40:07 +0900 (JST)
Subject: [ruby-changes:67557] 4e40b7ddb0 (master): [ruby/irb] Detect the variable class to show doc
https://git.ruby-lang.org/ruby.git/commit/?id=4e40b7ddb0 From 4e40b7ddb06b4ac806c85dabf2bd094fdd4bd6d0 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Thu, 2 Sep 2021 21:34:53 +0900 Subject: [ruby/irb] Detect the variable class to show doc https://github.com/ruby/irb/commit/33b9bec954 --- lib/irb/completion.rb | 15 +++++++++++---- test/irb/test_completion.rb | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index d1bb821..c7c0fb9 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -315,12 +315,19 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L315 end else - candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s} - candidates |= ReservedWords - if doc_namespace - candidates.find{ |i| i == input } + vars = eval("local_variables | instance_variables", bind).collect{|m| m.to_s} + perfect_match_var = vars.find{|m| m.to_s == input} + if perfect_match_var + eval("#{perfect_match_var}.class.name", bind) + else + candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s} + candidates |= ReservedWords + candidates.find{ |i| i == input } + end else + candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s} + candidates |= ReservedWords candidates.grep(/^#{Regexp.quote(input)}/) end end diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index ab57762..260b8a8 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -83,5 +83,11 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_completion.rb#L83 assert_include candidates, word end end + + def test_complete_variable + str_example = '' + 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 end end -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/