Created
October 2, 2012 13:51
-
-
Save ronan-mch/3819326 to your computer and use it in GitHub Desktop.
Ruby code for getting confirms from user
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 prompt(*args) | |
print(*args) | |
gets.chomp! | |
end | |
def confirm(*args) | |
answer = prompt(*args, "(Y/N)") | |
if (answer.downcase =~ /^y|^n/) | |
return answer =~ /y/ ? true : false | |
else | |
return confirm(*args) | |
end | |
end | |
really = confirm "Continue? " | |
puts really |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment