p() vs. puts() vs. print() in Rails
Use p
.
Rails has three printing methods, two are common, one is less so.
print
prints the string (to_s
) version of what is passed to it.
puts
works likeprint
but adds a newline\n
.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.