From efa56e7aa36b7aa02094ee4fa01d034bf4e60cdb Mon Sep 17 00:00:00 2001 From: Alan Savage Date: Fri, 10 Apr 2020 12:55:09 -0400 Subject: [PATCH] Add examples of using `p` in "Printing things" fixes rubymonsters/ruby-for-beginners#39 --- source/10-writing_methods/07-printing.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/10-writing_methods/07-printing.md b/source/10-writing_methods/07-printing.md index 655b583..e88a633 100644 --- a/source/10-writing_methods/07-printing.md +++ b/source/10-writing_methods/07-printing.md @@ -56,7 +56,7 @@ because it tells you exactly what the thing that you are looking at is. `puts` on the other hand tries to be smart. For example when you pass an array to `puts` then it will output each of the -objects on a separate line: +objects on a separate line, but `p` shows the array the same way it is declared: ```ruby $ irb @@ -65,10 +65,12 @@ $ irb 1 2 3 +> p something +[1, 2, 3] ``` Also, the output for numbers and strings that contain numbers is exactly the -same when you use `puts`: +same when you use `puts`, but `p` outputs strings surrounded with quotes: ```ruby $ irb @@ -76,6 +78,8 @@ $ irb 123 > puts "123" 123 +> p "123" +"123" ``` From the output of `puts` it often is not clear whether the object that you are