For "pretty print"
The pp
method defined in Object
is used to pretty print objects. Very useful for debugging.
The two methods p
and pp
take a variable number of arguments, which they return (allowing part of an expression to be displayed if necessary). Each object is independently formatted using the inspect
method.
The formatting will depend on the object you’re writing to. The default is $>
(aka STDOUT
). To change this, and the cutting width threshold, you need to use the PP gem directly. Don’t forget to include it (the pp
method of Object
does this automatically).
PS: If you plan to test with IRB, do not confuse what is printed by p
or pp
in previous examples and the return value printed automatically by IRB (using pp
too)!
Link to Ruby documentation for pp.