diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 0e34fc63aa..35767feeb7 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -373,7 +373,7 @@ module IRB if doc_namespace "String.#{candidates.find{ |i| i == message }}" else - select_message(receiver, message, candidates) + select_message(receiver, message, candidates.sort) end else @@ -390,7 +390,7 @@ module IRB else candidates = (bind.eval_methods | bind.eval_private_methods | bind.local_variables | bind.eval_instance_variables | bind.eval_class_constants).collect{|m| m.to_s} candidates |= ReservedWords - candidates.grep(/^#{Regexp.quote(input)}/) + candidates.grep(/^#{Regexp.quote(input)}/).sort end end end diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index fb10870820..8d7476b8f5 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -208,5 +208,16 @@ module TestIRB 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 + + def test_complete_sort_variables + xzy, xzy_1, xzy2 = '', '', '' + + xzy.clear + xzy_1.clear + xzy2.clear + + candidates = IRB::InputCompletor.retrieve_completion_data("xz", bind: binding, doc_namespace: false) + assert_equal(candidates, %w[xzy xzy2 xzy_1]) + end end end