Created
July 8, 2010 10:01
-
-
Save eregon/467825 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
Ceci est un essai de réponse en Ruby à: | |
http://lasts.goldzoneweb.info/pf.html |
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
class ValidationError < StandardError; end | |
def ask(question, answer_type = String, not_valid = nil, &validation) | |
begin | |
print "#{question} : " | |
answer = send(answer_type.name, gets.chomp) | |
raise ValidationError unless validation[answer] | |
answer | |
rescue ValidationError | |
puts not_valid if not_valid | |
retry | |
rescue | |
puts "Veuillez entrer un #{answer_type}" | |
retry | |
end | |
end | |
ask("Entrez votre nom") { |nom| nom.size > 0 } | |
ask("Entrez votre âge", Integer, | |
"Vous ne pouvez pas avoir un âge négatif.") { |age| age > 0 } | |
ask("Entrez votre mot de passe", String, | |
"Votre mot de passe doit faire au moins six caractères.") { |mdp| mdp.size >= 6 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment