module Kernel
Pretty-printer for Ruby objects.¶ ↑
Which seems better?¶ ↑
non-pretty-printed output by p is:
#<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 by pp
is:
#<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>
I like the latter. If you do too, this library is for you.
Usage¶ ↑
pp(obj)
output obj
to +$>+ in pretty printed format.
It returns nil
.
Output Customization¶ ↑
To define your customized pretty printing function for your classes, redefine a method pretty_print(pp
) in the class. It takes an argument pp
which is an instance of the class PP
. The method should use PP#text
, PP#breakable
, PP#nest
, PP#group
and PP#pp
to print the object.
Author¶ ↑
Tanaka Akira <akr@m17n.org>
Public Class Methods
pp(*objs)
click to toggle source
prints arguments in pretty form.
pp returns argument(s).
# File lib/project/pp.rb, line 56 def pp(*objs) # :doc: objs.each {|obj| PP.pp(obj) } objs.size <= 1 ? objs.first : objs end
Public Instance Methods
pretty_inspect()
click to toggle source
returns a pretty printed object as a string.
# File lib/project/pp.rb, line 48 def pretty_inspect PP.pp(self, '') end
Private Instance Methods
pp(*objs)
click to toggle source
prints arguments in pretty form.
pp returns argument(s).
# File lib/project/pp.rb, line 56 def pp(*objs) # :doc: objs.each {|obj| PP.pp(obj) } objs.size <= 1 ? objs.first : objs end