Skip to content

Instantly share code, notes, and snippets.

@rottenbytes
Created February 22, 2013 09:50
Show Gist options
  • Save rottenbytes/5012180 to your computer and use it in GitHub Desktop.
Save rottenbytes/5012180 to your computer and use it in GitHub Desktop.
def ask_question(question, opts={})
question = question + "[#{opts[:default]}] " if opts[:default]
STDOUT.print question
a = STDIN.readline.strip
if opts[:default]
a.empty? ? opts[:default] : a
else
a
end
end
x = ask_question("test Y/N/(A)ll/(Q)uit ", :default => "N")
puts "=> #{x}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment