puts "Enter a number: "
num1 = gets.chomp()
puts "Enter another number"
num2 = gets.chomp()
puts (num1 + num2)
Enter a number
5
Enter another number
2
52
Stringなので、足し算にならない。解決にはto_i使う
puts "Enter a number: "
num1 = gets.chomp()
puts "Enter another number"
num2 = gets.chomp()
puts (num1.to_i + num2.to_i)
Enter a number
5
Enter another number
2
7
Enter a number
5
Enter another number
2.5
7
小数点以下認識しない。解決にはto_f使う
puts (num1.to_f + num2.to_f)
Enter a number
5
Enter another number
2.5
7.5
以下のほうがソース綺麗
puts "Enter a number: "
num1 = gets.chomp().to_f
puts "Enter another number"
num2 = gets.chomp().to_f
puts (num1 + num2)
Enter a number
5.5
Enter another number
2.1
7.6