diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 9c3ea7836..e3ebe4abf 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -9,6 +9,30 @@ module IRB class BaseCompletor # :nodoc: + + # 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 + else elsif end ensure + false for + if in + module + next nil not + or + redo rescue retry return + self super + then true + undef unless until + when while + yield + ] + def completion_candidates(preposing, target, postposing, bind:) raise NotImplementedError end @@ -98,29 +122,6 @@ def inspect 'RegexpCompletor' end - # 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 - else elsif end ensure - false for - if in - module - next nil not - or - redo rescue retry return - self super - then true - undef unless until - when while - yield - ] - def complete_require_path(target, preposing, postposing) if target =~ /\A(['"])([^'"]+)\Z/ quote = $1 diff --git a/lib/irb/type_completion/completor.rb b/lib/irb/type_completion/completor.rb index 5eadc97f1..a0fc4d946 100644 --- a/lib/irb/type_completion/completor.rb +++ b/lib/irb/type_completion/completor.rb @@ -120,7 +120,7 @@ def candidates_from_result(result) end (scope_constants.compact | type.constants.map(&:to_s)).sort else - scope.constants.sort + scope.constants.sort | ReservedWords end in [:ivar, name, scope] ivars = scope.instance_variables.sort @@ -134,7 +134,7 @@ def candidates_from_result(result) in [:call, type, name, self_call] (self_call ? type.all_methods : type.methods).map(&:to_s) - HIDDEN_METHODS in [:lvar_or_method, name, scope] - scope.self_type.all_methods.map(&:to_s) | scope.local_variables + scope.self_type.all_methods.map(&:to_s) | scope.local_variables | ReservedWords else [] end