本文簡要介紹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類。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
