Skip to content
AgileLogics
4 min read

Printing Output: puts, print, and p

Prerequisites: Ruby syntax basics

Ruby has three everyday ways to print:

Method Adds a new line? Shows
puts Yes A friendly version for people
print No A friendly version, with no new line
p Yes A developer view that shows the type

Example

puts "Hello"
print "Same "
print "line"
puts
p "Hello"
p 42
puts nil
p nil
puts [1, 2]
p [1, 2]

Expected output

Hello
Same line
"Hello"
42

nil
1
2
[1, 2]

Line by line:

  • print twice keeps both words on one line; the bare puts then ends that line.
  • p "Hello" shows the quotes, so you can tell it's a string. That's why p is the go-to tool for debugging — it shows exactly what a value is.
  • puts nil prints an empty line, while p nil prints nil.
  • puts prints each element of an array on its own line; p shows the array itself.

Common mistakes

  • Debugging with puts and being confused when "" (an empty string) and nil both print as a blank line. Use p to see the difference.

Practice

Print Loading... and then done on the same line, followed by a new line.

Show solution
print "Loading..."
puts "done"