Created
August 19, 2009 10:01
-
-
Save crayment/170269 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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