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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
pis used to inspect a variable as a debug aide. It works printing the output of the method#inspect. For examplep foowill output the content offoo.inspect.Sometimes you need to debug complex variables or nested variables. In this case
pwill output a long line that is hard to understand. Instead,ppwill 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.ppdoes this calling the#pretty_inspectmethod (thepplibrary adds#pretty_inspectmethods to many classes such asString,ArrayorStruct).To remember:
p= print,pp= pretty print.