Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples of using p in "Printing things" #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions source/10-writing_methods/07-printing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,17 +65,21 @@ $ 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
> puts 123
123
> puts "123"
123
> p "123"
"123"
```

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