Question: I'm practicing a little with Ruby and I want to handle the age's input, for example if someone types "eleven" instead of 11, I want to show a message that, the person know he/she can't use a String. 

Here's my code

```
saludo = "Hola ¿Como te llamas?"

puts saludo
STDOUT.flush
#STDOUT es una constante global que almacena las salidas del programa. flush vacía cualquier dato almacenado, y por lo tanto, limpiará cualquier resultado anterior.
nombre = gets
STDOUT.flush
puts "Entonces te llamas #{nombre}"

puts "¿Cuantos años tienes?"
edad = Integer(gets.chomp)
#gets.chomp elimina el /n de gets
#El .to_i pasa el String a Integer
if edad > 0
  if edad >= 18
    puts "Eres mayor de edad, puedes votar y esas cosas"
  else
    puts "Tienes que moverte con el permiso de tus padres."
  end
else
  puts "prueba"
end    

```

Answer: 
If you want to check the datatype of the input, you can use something like this:

```
input = gets.chomp
input.class == Fixnum

```

Since, every input in ruby is taken as a string, you can convert the input to integer using `to_i` like:

```
input = gets.to_i

```

Check if the input value is 0 which is the default value taken by the strings converted to integer as below:

```
if input == 0
puts("Please enter an integer")

```
### A more Ruby way

Use a [**case-expression**](http://ruby-doc.org/core-2.4.1/doc/syntax/control_expressions_rdoc.html#label-case+Expression) which allows you to compare your input with string-ranges thus negating the need to use `String#to_i`:

```
#age.rb
loop do
  puts 'Enter age'
  case gets.chomp
  when /\D/
    puts 'Digits only, try again', '======================'
  when '0'..'17'
    puts 'too young'
    break
  when '18'..'120'
    puts 'old enough'
    break
  else
    puts 'Invalid age, try again', '======================'
  end
end

```

Using [`Kernel#loop`](http://ruby-doc.org/core-2.4.1/Kernel.html#method-i-loop) ensures you continue asking the user for an input until they enter a valid age. Valid ages are defined in the case-expression as `0 - 120`. If a valid age is entered the loop is broken with `break`.

---

### Running the code

```cl
$ ruby age.rb
Enter age
eleven
#Digits only, try again
#======================
Enter age
10000
#Invalid age, try again
#======================
Enter age
5
#too young

$ ruby vote.rb
Enter age
35
#old enough

```