Skip to content

Commit efa56e7

Browse files
committed
Add examples of using p in "Printing things"
fixes rubymonsters#39
1 parent a4ded42 commit efa56e7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: source/10-writing_methods/07-printing.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ because it tells you exactly what the thing that you are looking at is.
5656
`puts` on the other hand tries to be smart.
5757

5858
For example when you pass an array to `puts` then it will output each of the
59-
objects on a separate line:
59+
objects on a separate line, but `p` shows the array the same way it is declared:
6060

6161
```ruby
6262
$ irb
@@ -65,17 +65,21 @@ $ irb
6565
1
6666
2
6767
3
68+
> p something
69+
[1, 2, 3]
6870
```
6971

7072
Also, the output for numbers and strings that contain numbers is exactly the
71-
same when you use `puts`:
73+
same when you use `puts`, but `p` outputs strings surrounded with quotes:
7274

7375
```ruby
7476
$ irb
7577
> puts 123
7678
123
7779
> puts "123"
7880
123
81+
> p "123"
82+
"123"
7983
```
8084

8185
From the output of `puts` it often is not clear whether the object that you are

0 commit comments

Comments
 (0)