I’ve been trying to pick up Ruby and one of the things I was asking myself was the difference in the various ways you can output text.
- puts: displays text and adds a newline character
- print: displays text and doesn’t add a newline character (this means you must add newlines manually when using print)
- p: while it’s similar to puts in that it adds a newline, it calls
to_sThis is why p can be more useful for debugging since it shows what class an object belongs to.
More references for those interested