Case insensitive tab completion in Ruby


#1

I am using HighLine::Question.readline to achieve tab completion in Ruby. Below is the piece of code of tab_complete.rb which does that for me.

require "rubygems"
require "highline/import"

tab_complete = ["yes", "okay", "maybe", "no"]

selected = ask("Please say something: ", tab_complete) do |q|
  q.readline = true
end
p selected

-bash-4.1$ ruby tab_complete.rb
Please say something: yes
"yes"

The above code works fine for the items which are in the array, but I want to handle case-insensitive tab-completion. For example, if user enters upcase or downcase y and hit tab key it should get completes as downcase yes and that value should be saved in selected . Right now I get prompted to enter case-sensitive words as shown below:

-bash-4.1$ ruby tab_complete.rb
Please say something: Y
You must choose one of [yes, okay, maybe, no].
?  Please say something:

Any pointers on this will be really helpful to move forward.