本文简要介绍ruby语言中 PP类 的用法。
Ruby 对象的pretty-printer。
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>>
Pretty-printed 输出返回:
#<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) 到$>。
它返回 obj(s) 。
输出定制
要为您的类定义自定义的漂亮打印函数,请在类中重新定义方法#pretty_print(pp)。
#pretty_print 采用pp 参数,它是 PP 类的一个实例。该方法使用 text 、 breakable 、 nest 、 group 和 pp 来打印对象。
Pretty-Print JSON
至 pretty-print JSON 请参阅 JSON#pretty_generate 。
相关用法
- Ruby PPMethods.comma_breakable用法及代码示例
- Ruby PPMethods.object_group用法及代码示例
- Ruby PPMethods.seplist用法及代码示例
- Ruby PrettyPrint.current_group用法及代码示例
- Ruby Pathname.<=>用法及代码示例
- Ruby Pathname.children用法及代码示例
- Ruby Process.groups用法及代码示例
- Ruby Process.wait2用法及代码示例
- Ruby Process.getpgrp用法及代码示例
- Ruby Proc.eql?用法及代码示例
- Ruby PTY.open用法及代码示例
- Ruby PrettyPrint.genspace用法及代码示例
- Ruby PKey.sign_raw用法及代码示例
- Ruby Profiler模块用法及代码示例
- Ruby Process.setproctitle用法及代码示例
- Ruby Process.setrlimit用法及代码示例
- Ruby Proc.prc ==用法及代码示例
- Ruby Profiler.raw_data用法及代码示例
- Ruby Process.uid用法及代码示例
- Ruby Pathname.descend用法及代码示例
- Ruby Process.pid用法及代码示例
- Ruby Proc.ruby2_keywords用法及代码示例
- Ruby Pathname.getwd用法及代码示例
- Ruby PKey.generate_parameters用法及代码示例
- Ruby Proc.new用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 PP类。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
