Skip to content

Instantly share code, notes, and snippets.

@dbkbali
Created January 10, 2016 00:43
Show Gist options
  • Save dbkbali/45924701f4ab48f2b505 to your computer and use it in GitHub Desktop.
Save dbkbali/45924701f4ab48f2b505 to your computer and use it in GitHub Desktop.
Basic Psuedocode and Ruby for Creating a Repl
require "pry"
### REPL EXAMPLE
#
# ARGV array holds any additional parameters when the program is run
#
# STDIN.gets.chomp - waits for the user to input on the terminal
#
#
def command_line_repl
case ARGV[0]
when "help"
puts "Here is a list of available commands:"
puts "find 1 - find candidate with id 1"
puts "all - all candidates"
puts "qualified - qualified candidates"
puts "quit"
else
puts "enter your command to continue"
puts "available commands are: find [id], qualified, all, or quit"
input = ""
while !input.eql?("quit")
# gets requests user to input a command
# stored in variable input
input = STDIN.gets.chomp
commands_array = input.chomp.split(' ')
if commands_array.length.eql?(1) && !commands_array[0].match(/quit/i)
puts "command of qualified or all detected"
# if statements to run appropriate methods qualified or all
else
puts "need to code here to run the find command if present"
# check command_array for find 1 command
# ie. commands_array[0] == "find"
# then id = command_array[1]
# execute find method or exit for next loop
end
end
end
end
command_line_repl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment