class PP
A pretty-printer for Ruby objects.
What PP Does
Standard output by #p returns this: #<PP:0x81fedf0 @genspace=#<Proc:0x81feda0>, @group_queue=#<PrettyPrint::GroupQueue:0x81fed3c @queue=[[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], []]>, @buffer=[], @newline=ā\nā, @group_stack=[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], @buffer_width=0, @indent=0, @maxwidth=79, @output_width=2, @output=#<IO:0x8114ee4>>
Pretty-printed output returns this: #<PP:0x81fedf0 @buffer=[], @buffer_width=0, @genspace=#<Proc:0x81feda0>, @group_queue= #<PrettyPrint::GroupQueue:0x81fed3c @queue= [[#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>], []]>, @group_stack= [#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>], @indent=0, @maxwidth=79, @newline=ā\nā, @output=#<IO:0x8114ee4>, @output_width=2>
Usage
pp(obj) #=> obj pp obj #=> obj pp(obj1, obj2, ...) #=> [obj1, obj2, ...] pp() #=> nil
Output obj(s) to $> in pretty printed format.
It returns obj(s).
Output Customization
To define a customized pretty printing function for your classes, redefine method pretty_print(pp) in the class. Note that require 'pp' is needed before redefining pretty_print(pp).
pretty_print takes the pp argument, which is an instance of the PP class. The method uses text, breakable, nest, group and pp to print the object.
Pretty-Print JSON
To pretty-print JSON refer to JSON#pretty_generate.
Author
Tanaka Akira akr@fsij.org
Attributes
bool?
Returns the sharing detection flag as a boolean value. It is false (nil) by
default.
Sets the sharing detection flag to b.
Public Class Methods
(untyped obj, Module mod, interned meth, *untyped args) ?{ (*untyped, **untyped) → untyped } → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/pp/0/pp.rbs, line 257
def self.mcall: (untyped obj, Module mod, interned meth, *untyped args) ?{ (*untyped, **untyped) -> untyped } -> untyped
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/pp/0/pp.rbs, line 246
def self.pp: (_PrettyPrint obj, ?_LeftShift out, ?Integer width) -> untyped
(_PrettyPrint obj, ?_LeftShift out) → untyped
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/pp/0/pp.rbs, line 256
def self.singleline_pp: (_PrettyPrint obj, ?_LeftShift out) -> untyped
Outputs obj to out like PP.pp but with no indent and newline.
PP.singleline_pp returns out.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/pp/0/pp.rbs, line 233
def self.width_for: (untyped out) -> Integer
Returns the usable width for out. As the width of out: 1. If out is assigned to a tty device, its width is used. 2. Otherwise, or it could not get the value, the COLUMN environment variable is assumed to be set to the width. 3. If COLUMN is not set to a non-zero number, 80 is assumed.
And finally, returns the above width value - 1. * This -1 is for Windows command prompt, which moves the cursor to the next line if it reaches the last column.