Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Ruby Basics!
You have completed Ruby Basics!
Sometimes calling "puts" with a Ruby value doesn't reveal everything about it. This is why Ruby provides a method named "p" in addition to "puts" and "print". The "p" method allows us to inspect the values we pass to it, to print them out approximately the same way they would appear in Ruby code.
- Sometimes calling
puts
with a Ruby value doesn't reveal everything about it. - These calls to
puts
appear to output nothing at all, even though we're passing Ruby objects to each one.- A string with nothing but space characters
- An empty string
- The special value
nil
and an empty array, important concepts that we'll discuss in future courses - All appear empty.
puts " "
puts ""
puts nil
puts []
Output:
This is why Ruby provides a method named p
in addition to puts
and print
. The p
method allows us to inspect the values we pass to it, to print them out approximately the same way they would appear in Ruby code.
p " "
p ""
p nil
p []
Output:
" "
""
nil
[]
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up