Skip to content

Instantly share code, notes, and snippets.

@crayment
Created August 19, 2009 10:01
Show Gist options
  • Save crayment/170269 to your computer and use it in GitHub Desktop.
Save crayment/170269 to your computer and use it in GitHub Desktop.
def ask message, answer = /.*/, add_options_string = answer == /.*/ ? false : true
message = message + ' (' + answer.source + ')' if add_options_string
begin
print message
input = STDIN.gets.chomp
end while input !~ /^#{answer}$/
input
end
def ask_with_default default, *params
input = ask(params)
return input unless input.gsub(' ', '').empty?
default
end
ask 'Press enter to continue.'
ask 'Is this awesome?', /yes|no/
ask 'Is this awesome? (yes or no)', /yes|no/, false
ask_with_default '/default/path/', 'Installation path? (/default/path/)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment