Playing with the ruby console I am wondering how I can read some input from the console. Ruby ships with the method gets that makes easy to read console input. Just try the following code:

print "What is your name? "
$stdout.flush
name = gets
puts 'Hi ' + name + '!!!'

# => Hi andrea
# !!!

When the console asks for your name just type it. The ruby program will read the console input and will welcome you. You will note that  a new line is added after that the variable name is  printed out. This is the default behaviour of the gets function. Gets add a new line after any variable that memorize. If this is not desired  you can call the method chomp on the gets result and the newline is suppressed.

Change your code as follows and the new line will not be printed anymore:

print "What is your name? "
$stdout.flush
name = gets.chomp
puts 'Hi ' + name + '!!!'

#=> Hi andrea!!!

andreacfm