Pretty-printer
p による pretty-print されてない出力:
#<PP:0x81a0d10 @stack=[], @genspace=#<Proc:0x81a0cc0>, @nest=[0], @newline="\n", @buf=#<PrettyPrint::Group:0x81a0c98 @group=0, @tail=0, @buf=[#<PrettyPrint::Group:0x81a0ba8 @group=1, @tail=0, @buf=[#<PrettyPrint::Text:0x81a0b30 @tail=2, @width=1, @text="[">, #<PrettyPrint::Group:0x81a0a68 @group=2, @tail=1, @buf=[#<PrettyPrint::Text:0x81a09f0 @tail=1, @width=1, @text="1">], @singleline_width=1>, #<PrettyPrint::Text:0x81a0a7c @tail=0, @width=1, @text=",">, #<PrettyPrint::Breakable:0x81a0a2c @group=2, @genspace=#<Proc:0x81a0cc0>, @newline="\n", @indent=1, @tail=2, @sep=" ", @width=1>, #<PrettyPrint::Group:0x81a09c8 @group=2, @tail=1, @buf=[#<PrettyPrint::Text:0x81a0950 @tail=1, @width=1, @text="2">], @singleline_width=1>, #<PrettyPrint::Text:0x81a0af4 @tail=0, @width=1, @text="]">], @singleline_width=6>], @singleline_width=6>, @sharing_detection=false>
pp による pretty-print された出力:
#<PP:0x40d0688
@buf=
#<PrettyPrint::Group:0x40d064c
@buf=
[#<PrettyPrint::Group:0x40d05d4
@buf=
[#<PrettyPrint::Text:0x40d0598 @tail=2, @text="[", @width=1>,
#<PrettyPrint::Group:0x40d0534
@buf=[#<PrettyPrint::Text:0x40d04f8 @tail=1, @text="1", @width=1>],
@group=2,
@singleline_width=1,
@tail=1>,
#<PrettyPrint::Text:0x40d053e @tail=0, @text=",", @width=1>,
#<PrettyPrint::Breakable:0x40d0516
@genspace=#<Proc:0x40d0656>,
@group=2,
@indent=1,
@newline="\n",
@sep=" ",
@tail=2,
@width=1>,
#<PrettyPrint::Group:0x40d04e4
@buf=[#<PrettyPrint::Text:0x40d04a8 @tail=1, @text="2", @width=1>],
@group=2,
@singleline_width=1,
@tail=1>,
#<PrettyPrint::Text:0x40d057a @tail=0, @text="]", @width=1>],
@group=1,
@singleline_width=6,
@tail=0>],
@group=0,
@singleline_width=6,
@tail=0>,
@genspace=#<Proc:0x40d0656>,
@nest=[0],
@newline="\n",
@sharing_detection=false,
@stack=[]>
pp(obj)obj を $> に pretty print で出力します。
nil を返します。
Object#pretty_inspectself を pp で表示したときの結果を文字列として返します。
あなたのクラスについて pritty print するカスタマイズ機能を定義するには、
そのクラスで pretty_print(pp) を再定義します。
このメソッドのがとる引数 pp は PP クラスのインスタンスです。
このメソッドは出力に際して PP#text, PP#breakable, PP#nest, PP#group および
PP#pp を使います。
--> PP