From: Sebastian Hungerecker Date: 2009-01-12T07:34:12+09:00 Subject: Re: Checking if input == Integer/String? Ulrich Holtzhausen wrote: > puts "What is your favourite number?" > num = gets.to_i > if num != Integer >   puts "Please type a number" > else >   better = num + 1 >   puts "Hah! #{num} is pathetic! #{better} is a much better number!!!" > end > > Somewhere along the line there's a mistake however, but I take it you > guru's can see what I'm trying to do here? > > How can I check if the variable 'num' is an integer and if not, ask the > user to re-input with an integer? to_i always returns an Integer (if the string isn't a valid number, it just returns 0). If you don't want that you can use Integer(str) which raises an exeption if the string is not a valid number. Also note that 4 == Integer is false. Only Integer is == Integer. num.is_a? Integer would work, but as I said, to_i always returns an Integer, so that would always be true. HTH, Sebastian -- NP: Die Apokalyptischen Reiter - Auferstehen Soll In Herrlichkeit Jabber: sepp2k@jabber.org ICQ: 205544826