Reading input (stdin)
Read what you type in the IDE's Input tab with gets or $stdin.each_line.
Runs in Zerethon IDE · Ruby 4.0
Official Ruby documentation ↗
A run cannot ask questions while it runs. Type the program's input in the Input tab before you press Run; gets then reads it one line at a time.
main.rb
name = gets.chomp
a, b = gets.split.map(&:to_i)
puts "Hello, #{name}! #{a} + #{b} = #{a + b}"
Input (stdin)
Ada 3 4
Output
Hello, Ada! 3 + 4 = 7
main.rb
numbers = $stdin.each_line.map(&:strip).reject(&:empty?).map(&:to_i)
puts "total: #{numbers.sum}"
Input (stdin)
5 10 15
Output
total: 30
Watch out: gets returns nil when there is nothing left to read, so gets.chomp fails with undefined method 'chomp' for nil (NoMethodError). Add the input in the Input tab, one value per line.