Skip to content

Instantly share code, notes, and snippets.

@narutaro
Created September 6, 2020 02:24
Show Gist options
  • Save narutaro/b9dacb334de29ac57d1cb0f07e410288 to your computer and use it in GitHub Desktop.
Save narutaro/b9dacb334de29ac57d1cb0f07e410288 to your computer and use it in GitHub Desktop.
[Tab completion] REPL tab completion in ruby #tab #repl
require "readline"
pet_store = [ "pet", "store", "user"]
Readline.completion_proc = proc do |input|
pet_store.select { |name| name.start_with?(input) }
end
while input = Readline.readline("$ ", false)
if input
break if input == "q"
p Readline.line_buffer.split if !input.empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment