From: Captain Ishido Date: 2013-07-30T19:03:16+09:00 Subject: How to check an input IS an integer ? Hi everyone ! I have a little problem since a few days. I would like to check that my user (I am writing a small program) had type an integer while I asked him. So, I thought I could check the class or the 'type_of'. But these methods don't work. Here is my try : cat check_class.rb #!/usr/bin/env ruby # -*- coding: utf-8 -*- # check_class.rb # Tests sur les class # Ici, on verifie que le flux envoyé # par le clavier est bien un entier. # Autrement, on boucle. print "Veuillez entrer un entier (1) : " reponse = readline.chomp while reponse.kind_of?(Integer) == false do print "Veuillez entrer un entier (2) : " reponse = readline.chomp end If someone has an idea... :/ ------------------------------ Sources : http://fr.wikibooks.org/wiki/Math%C3%A9matiques_avec_Python_et_Ruby/Nombres_entiers_en_Ruby ('tests sur les entiers' section) http://blog.escarworld.com/post/2011/04/19/is_a,-kind_of,-connaitre-la-classe-d-une-variable -- Cordialement. +-------------------------------------------------+ | Ensemble, libérons Internet ! | +----------------+--------------------------------+ | Linux à Nantes | http://www.linux-nantes.org/ | +----------------+--------------------------------+ | Projet Bépo | http://bepo.fr/ | +----------------+--------------------------------+ | Site perso | http://captain.ishido.free.fr | +----------------+--------------------------------+ | Message tapé en Bépo sur un Typematrix 2030 USB | +-------------------------------------------------+