File tree 1 file changed +6
-2
lines changed
source/10-writing_methods
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ because it tells you exactly what the thing that you are looking at is.
56
56
` puts ` on the other hand tries to be smart.
57
57
58
58
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 :
60
60
61
61
``` ruby
62
62
$ irb
@@ -65,17 +65,21 @@ $ irb
65
65
1
66
66
2
67
67
3
68
+ > p something
69
+ [1 , 2 , 3 ]
68
70
```
69
71
70
72
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 :
72
74
73
75
``` ruby
74
76
$ irb
75
77
> puts 123
76
78
123
77
79
> puts " 123"
78
80
123
81
+ > p " 123"
82
+ " 123"
79
83
```
80
84
81
85
From the output of ` puts ` it often is not clear whether the object that you are
You can’t perform that action at this time.
0 commit comments