PP
Parent:PrettyPrintIncluded模块:PP :: PPMethods
一个适合Ruby对象的漂亮打印机。
所有例子都假设你已经加载了PP类:
require 'pp'PP做什么
标准输出由p返回:
#<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>>好的打印输出返回这个:
#<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>用法
pp(obj) #=> obj
pp obj #=> obj
pp(obj1, obj2, ...) #=> [obj1, obj2, ...]
pp() #=> nil输出obj(s)到$>好的打印格式。
It returns obj(s).
输出定制
为您的类定义好的的打印功能,重新定义类中的方法#pretty_print(pp)。
#pretty_print采用pp参数,这是PP类的一个实例。该方法使用text,breakable,nest,group和pp来打印对象。
Pretty-Print JSON
要好地打印JSON,请参阅JSON#pretty_generate。
以布尔值形式返回共享检测标志。它默认为false。
Public Class Methods
pp(obj, out=$>, width=79) Show source
输出obj为宽度out很好的width列的格式。
如果out省略,$>则假定。如果width省略,则假定为79。
::pp returns out.
# File lib/pp.rb, line 97
def PP.pp(obj, out=$>, width=79)
q = PP.new(out, width)
q.guard_inspect_key {q.pp obj}
q.flush
#$pp = q
out << "\n"
endsingleline_pp(obj, out=$>) Show source
输出obj为out像:: pp,但没有缩进和换行符。
::singleline_pp returns out.
# File lib/pp.rb, line 109
def PP.singleline_pp(obj, out=$>)
q = SingleLine.new(out)
q.guard_inspect_key {q.pp obj}
q.flush
out
end本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

