22件ヒット
[1-22件を表示]
(0.044秒)
検索結果
-
Object
# pretty _ print(pp) -> () (18131.0) -
PP.pp や Kernel.#pp がオブジェクトの内容を出力するときに 呼ばれるメソッドです。PP オブジェクト pp を引数として呼ばれます。
...義します。
そのとき pretty_print メソッドは指定された pp に対して表示したい自身の内容を追加して
いかなければいけません。いくつかの組み込みクラスについて、
pp ライブラリはあらかじめ pretty_print メソッドを定義して......PP オブジェクトです。
//emlist[][ruby]{
require 'pp'
class Array
def pretty_print(q)
q.group(1, '[', ']') {
q.seplist(self) {|v|
q.pp v
}
}
end
end
//}
@see Object#pretty_print_cycle, Object#inspect, PrettyPrint#text, PrettyPrint#group, PrettyPrint#breakab......@param pp PP オブジェクトです。
//emlist[][ruby]{
class Array
def pretty_print(q)
q.group(1, '[', ']') {
q.seplist(self) {|v|
q.pp v
}
}
end
end
//}
@see Object#pretty_print_cycle, Object#inspect, PrettyPrint#text, PrettyPrint#group, PrettyPrint#breakable... -
pp (30.0)
-
オブジェクトなどを見やすく出力するためのライブラリです。
...>
=== 出力のカスタマイズ
あるクラスの pp の出力をカスタマイズしたい場合は、
そのクラスで pretty_print メソッドと pretty_print_cycle メソッドを再定義します。
このメソッドは PP オブジェクトを引数として pp 実行時に呼ば......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(',')
q.breakable
end
q.pp k......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(',')
q.breakable
end
q.pp k...