p() vs. puts() vs. print() in Rails

Use p.

Rails has three printing methods, two are common, one is less so.

  1. print prints the string (to_s) version of what is passed to it.
  2. puts works like print but adds a newline \n.
  3. p prints the .inspect version of what is passed to it, along with the trailing newline.

Personally, i type some form of:

puts some_object.inspect  

multiple times a day. No more. This statement functions identically to:

p some_object  

11 characters less, and typos are nearly impossible. Type less, code more.

Building great products is hard. Let's get better at it.
Author image
Written by Ben
Denver, CO
VP of Engineering at MeetMindful. Have feedback or questions? Want to chat? Send me an email.