collimarco collimarco - 6 months ago 50
Ruby Question

p vs puts in Ruby

Is there any difference between

p
and
puts
in Ruby?

Answer

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).