I did do some searching, but can't find an answer to simple question.
What is difference between p
and pp
in Ruby? I know you need to require 'pp'
. Besides that what are the differences?
Short quotations If you are directly quoting from a work, you will need to include the author, year of publication, and page number for the reference (preceded by "p." for a single page and “pp.” for a span of multiple pages, with the page numbers separated by an en dash).
If you're referring to only one page, use the abbreviation p. and if there are multiple pages, use pp. This is how you can abbreviate the word page and pages.
P for Press (used for academic presses) p. for page, pp. for pages.
Abbreviation of pages. (plural of p.) Abbreviation of past participle.
p
is used to inspect a variable as a debug aide. It works printing the output of the method #inspect
. For example p foo
will output the content of foo.inspect
.
Sometimes you need to debug complex variables or nested variables. In this case p
will output a long line that is hard to understand. Instead, pp
will put try to arrange the content of the variable so that it is easier to understand, for example indenting nested arrays or using one line for each instance variable of a complex object. pp
does this calling the #pretty_inspect
method (the pp
library adds #pretty_inspect
methods to many classes such as String
, Array
or Struct
).
To remember: p
= print, pp
= pretty print.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With