module Terraformer class UserInputError < RuntimeError end class UserInputMaxAttemptsError < RuntimeError end class UserInput MAX_ATTEMPTS = 10 class << self def get_input response = gets response.chomp end def ask(message, success, failure) (0..MAX_ATTEMPTS).each do |i| puts "#{message} [#{success}/#{failure}]" response = get_input if response.downcase == success.downcase || response == "" return true elsif response.downcase == failure.downcase puts "Exiting" raise UserInputError end end raise UserInputMaxAttemptsError end end end end