Developers learning ruby for the first time tend to learn puts
before or around the same time as p
. Both methods print to the terminal (or the server, if you're using rails or sinatra). puts
seems like a nice counterpoint to gets
, as in gets.chomp
: gets
gets information from the user, and puts
puts it back on their screen. I'm inclined to disagree with this inclination strongly and say to never use puts
(it's objectively worse), but there are cases where it's useful.
If you're writing a program that runs in the terminal, puts
can be useful. It's a more aesthetic way to print information and directions to the user. I could argue that anyone using the terminal to run your program is likely a developer and won't have any problem with seeing quotation marks, but I won't because I know I've been known to not give UI as much credence as it deserves.
In essentially any other case when you want something printed, use p
. This is a great tool for debu