Printing to the Ruby console
When you're learning a new programming language, it is important to see your program's output. This guide can be used in an online REPL environment (like our variable lesson) or in the Unix Terminal by typing irb
, which will open an interactive Ruby session.
Using puts
In this lesson, we are going to learn the different options available to print messages to the Ruby console. The first way is to use the puts
method. Consider this example:
puts "A string"
The preceding line will display the content, A string
.
Using p
Another way to print to the console is as follows:
p "B string"
The difference between these two methods is that the former method will not return any value back to you, whereas the latter one will return a value. The following image shows this difference:

You will see that the puts
method returns a value of nil
:

The second option returns the value.
Though this difference may not be much now, you will discover how important this is as we progress through the...