collimarco collimarco - 1 year ago 123
Ruby Question

p vs puts in Ruby

Is there any difference between

in Ruby?

Answer Source

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