Hello Foo STDIN and strip


The solution is to remove the newline from the end of the string. We can do this using the strip method:

examples/intro/hello_foo_stdin_strip.rb
print "Type in your name: "
person = STDIN.gets.strip

puts "Hello #{person}, how are you?"

Now if we run the program and identify as Bar, the output will look the way we wanted:


Hello Bar, how are you?