Created
September 6, 2020 02:24
-
-
Save narutaro/b9dacb334de29ac57d1cb0f07e410288 to your computer and use it in GitHub Desktop.
[Tab completion] REPL tab completion in ruby #tab #repl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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