Class: PP
Overview
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 [email protected]
Defined Under Namespace
Modules: ObjectMixin, PPMethods Classes: SingleLine
Constant Summary collapse
- VERSION =
The version string
"0.6.2"
Class Attribute Summary collapse
-
.sharing_detection ⇒ Object
Returns the sharing detection flag as a boolean value.
Method Summary
Methods included from PPMethods
#check_inspect_key, #comma_breakable, #guard_inspect_key, #object_address_group, #object_group, #pop_inspect_key, #pp, #pp_hash, #pp_hash_pair, #pp_object, #push_inspect_key, #seplist
Class Attribute Details
.sharing_detection ⇒ Object
Returns the sharing detection flag as a boolean value. It is false by default.
125 126 127 |
# File 'lib/pp.rb', line 125 def sharing_detection Ractor.current[:pp_sharing_detection] end |