Q:

Ruby -- 'gets' adds newline character

I wrote this:
print "Enter your name:"
name = gets
puts "Hello #{name}. Please to meet you." 

and the result was like this:
Hello Moemen
. Pleased to meet you

Why is the remainder of the string after the variable continued in another line? I want it to be "Hello Moemen. Pleased to meet you." Am I missing something?
I'm using sublime text 2, and I couldn't get the gets method to let me input data; it just prints the outcome in the console without giving me a chance to input anything. Any idea?

A:

When you use gets, the input is going to be followed by a newline so you will need to strip the newline before printing it out.
print "Enter your name:"
name = gets.chomp
puts "Hello #{name}. Pleased to meet you."

That should solve your problem.

