Print vs Puts vs P vs putc

  1. Print:
  • Doesn't move to the cursor to the new line.
  • Same as .print in Java instead of .println
  1. Puts:
  • Creates a new line and moves the cursor to the new line.
  • Same as .prinln in Java.
  1. P:
  • Displays the raw object.
  • Even espace characters on a string is displayed.
  • Helpful for debugging.
  1. putc
  • Only prints 1 character at a time.
[12] pry(main)> print "test"
test=> nil
[10] pry(main)> puts "test \n"
test
=> nil
[11] pry(main)> p "test \n"
"test \n"
=> "test \n"

For more details: https://www.rubyguides.com/2018/10/puts-vs-print/