p vs puts in Ruby

p foo prints foo.inspect followed by a newline, i.e. it prints the value of inspect instead of to_s, which is more suitable for debugging (because you can e.g. tell the difference between 1"1" and "2\b1", which you can’t when printing without inspect).

Leave a Comment