RockPaperScissors

LizardSpock

Ruby CLI User Input Using Gets

| Comments

Using a while true loop with ‘gets’ and a case statement, can create a compact command line interface for ruby scripts.

while true
  puts "'q' to quit, 'c' to continue"
  command = gets
  case
    when command.match(/^q/) then
      puts "Quit"
      break
    when command.match(/^c/) then
      puts "Continue"
  end # case
end # while true

Comments