ruby read stdin

input = gets.chomp
puts "You entered: #{input}"
  1. input = gets.chomp: This line reads input from the standard input (keyboard by default) and assigns it to the variable input. gets is a method that retrieves a line of text from the standard input, while chomp removes the newline character from the end of the input.

  2. puts "You entered: #{input}": This line prints out a message along with the content of the input variable using string interpolation. The puts method outputs the specified message to the standard output (usually the console). The #{input} within the string interpolates the value stored in the input variable.