Skip to content

Instantly share code, notes, and snippets.

@MilanGrubnic70
MilanGrubnic70 / puts_print_p.md
Last active June 13, 2022 19:22
puts vs. print vs. p

#puts vs. print vs. p ###The 'puts' (short for "put string") and 'print' commands are both used to display the results of evaluating Ruby code. ###Both 'puts' and 'print' call the 'to_s' method on the object AND return nil.

###The primary difference between them is that 'puts' adds a newline after executing, and 'print' does not. ###They don't RETURN anything so the RETURN value is nil. ###Using 'p' calls the 'inspect' method on the object.

print "Milan"
Milan => nil