MΓ³dulo 01 Β· Ruby Basics β LecciΓ³n 6 de 6 Β· ~8 min
puts, p, and Running Files
puts vs. p vs. inspect
Ruby has two everyday printing methods, and they behave differently β mixing them up is a classic first-week confusion:
putsprints a human-readable version and adds a trailing newline. Onnilit prints nothing but a blank line. On a string, no quotes show.pprints the.inspectform β the DEBUG view, quotes included β and returns the value itself, which makes it handy inside a chain while debugging.
puts "Mochi" # Mochi p "Mochi" # "Mochi" (quotes shown) puts nil # (blank line) p nil # nil
Reach for puts when a script talks to a human. Reach for p when you're debugging and need to see exactly what a value IS β a symbol vs. a string, nil vs. an empty string, etc.