Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hello Foo using puts

  • puts
  • ,

It is not enough to print the name of the programmer, we would also want to greet the programmer.

We print the first part of the message, the variable, and the last part of the message in a single call to puts. We need to separate these parts with a comma (,).

person = "Foo"

puts "Hello ", person, ", how are you?"

We got everything on the screen, but we are slightly disappointed as puts put each part of our message on a separate line. That's not really nice.

Hello 
foo
, how are you?

In more technical terms, puts printed a newline after printing each one of its parameters.