ruby-changes:60082
From: Nobuhiro <ko1@a...>
Date: Sat, 15 Feb 2020 22:42:22 +0900 (JST)
Subject: [ruby-changes:60082] 961630126b (master): [ruby/irb] fix reserved words and completion for them
https://git.ruby-lang.org/ruby.git/commit/?id=961630126b From 961630126b8081ea57b57cde3184e9ecfd86ff96 Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI <nov@y...> Date: Wed, 12 Feb 2020 19:16:12 +0900 Subject: [ruby/irb] fix reserved words and completion for them https://github.com/ruby/irb/commit/6184b227ad diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 8c0474d..7236747 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -17,11 +17,12 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L17 # Set of reserved words used by Ruby, you should not use these for # constants or variables ReservedWords = %w[ + __ENCODING__ __LINE__ __FILE__ BEGIN END alias and begin break case class - def defined do + def defined? do else elsif end ensure false for if in @@ -255,7 +256,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb/completion.rb#L256 else candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s} - conditions |= ReservedWords + candidates |= ReservedWords if doc_namespace candidates.find{ |i| i == input } diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index d4072fe..a765bbf 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -35,5 +35,17 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_completion.rb#L35 def test_complete_symbol_failure assert_nil(IRB::InputCompletor::PerfectMatchedProc.(":aiueo", bind: binding)) end + + def test_complete_reserved_words + candidates = IRB::InputCompletor.retrieve_completion_data("de", bind: binding) + %w[def defined?].each do |word| + assert_include candidates, word + end + + candidates = IRB::InputCompletor.retrieve_completion_data("__", bind: binding) + %w[__ENCODING__ __LINE__ __FILE__].each do |word| + assert_include candidates, word + end + end end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/