Getting User Input

Getting user input from the terminal is super simple:

puts "Enter a number:"
num = gets

puts "You've entered #{num}"

Example: Add user input to an array

arr = [] of Int8

p "Enter a number between -128 to 127:"
num = gets

# Let's imagine the user entered 48
# The type of the variable num will be:
p typeof(num) # => Compile-time type: (String | Nil)
p num.class   # => Run-time type: String

# Check to make sure num is not nil
if num
  arr << num.to_i8
end

p arr

Multiple numbers:

arr = [] of Int8

p "Enter a number between -128 to 127 and hit enter:"
num = gets

while num = gets
  arr << num.to_i8
end
p arr