11件ヒット
[1-11件を表示]
(0.093秒)
検索結果
先頭1件
-
pp (25.0)
-
オブジェクトなどを見やすく出力するためのライブラリです。
...>
=== 出力のカスタマイズ
あるクラスの pp の出力をカスタマイズしたい場合は、
そのクラスで pretty_print メソッドと pretty_print_cycle メソッドを再定義します。
このメソッドは PP オブジェクトを引数として pp 実行時に呼ば......でもあります。
以下は Hash の pretty printing のカスタマイズの例です。
//emlist[][ruby]{
require 'pp'
class Hash
def pretty_print(q)
q.group(2, "<hash>") do
q.breakable
first = true
self.each{|k, v|
unless first
q.text(',')......else
q.pp v
end
end
first = false
}
end
q.breakable
q.text "</hash>"
end
def pretty_print_cycle(q)
q.text(empty? ? '{}' : '{...}')
end
end
h = {:a => 'a'*5, :b => 'b'*10, :c => 'c'*20, :d => 'd'*30}
pp h
#=>
# <hash>
# :d......メソッドでもあります。
以下は Hash の pretty printing のカスタマイズの例です。
//emlist[][ruby]{
class Hash
def pretty_print(q)
q.group(2, "<hash>") do
q.breakable
first = true
self.each{|k, v|
unless first
q.text(',')...