Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > prettyprintライブラリ > PrettyPrintクラス
クラス・モジュールの継承リスト: PrettyPrint < Object < Kernel < BasicObject
pretty printing アルゴリズムのためのクラスです。改行の位置を探し、きれいなインデントを施します。
デフォルトでは、このクラスは文字列を扱います。また、文字1バイトが出力幅の中で1カラムを占めると仮定しています。しかし、以下のメソッドに対して適切な引数を与えることで、そうでない場合にも利用できます。
ですので、このクラスは以下のようなことにも応用が可能です。
定義 | 説明 | |
---|---|---|
format(output = '', maxwidth = 79, newline = "\n", genspace = lambda{|n| ' ' * n}) {|pp| ...} -> object
|
PrettyPrint オブジェクトを生成し、それを引数としてブロックを実行します。与えられた output を返します。 |
|
new(output = '', maxwidth = 79, newline = "\n") -> PrettyPrint
|
pretty printing のためのバッファを生成します。 output は出力先です。output は << メソッドを持っていなければなりません。 << メソッドには
のどれかひとつが引数として与えられます。 |
|
singleline_format(output = '', maxwidth = 79, newline = "\n", genspace = lambda{|n| ' ' * n}) {|pp| ...} -> object
|
PrettyPrint オブジェクトを生成し、それを引数としてブロックを実行します。 PrettyPrint.format に似ていますが、改行しません。 |
定義 | 説明 | |
---|---|---|
breakable(sep = ' ') -> ()
|
「必要ならここで改行出来る」ということを自身に通知します。もしその位置で改行されなければ、width カラムのテキスト sep が出力の際にそこに挿入されます。 |
|
flush -> ()
|
バッファされたデータを出力します。 |
|
genspace -> Proc
|
空白を生成する Proc を返します。 |
|
group(indent = 0, open_obj = '', close_obj = '', open_width = open_obj.length, close_width = close_obj.length) {...} -> ()
|
与えられたブロックを実行します。ブロック内で自身に追加される文字列やオブジェクトは、1行にまとめて表示してもよい同じグループに属すると仮定されます。 |
|
indent -> Integer
|
現在のインデントの深さを返します。 |
|
maxwidth -> Integer
|
自身の幅を返します。 |
|
nest(indent) {...} -> ()
|
自身の現在のインデントを indent だけ増加させてから、ブロックを実行し、元に戻します。 |
|
newline -> String
|
自身の改行文字を返します。 |
|
output -> object
|
自身の output を返します。 |
|
text(obj) -> ()
|
obj を width カラムのテキストとして自身に追加します。 |
!
!=
__id__
__send__
instance_eval
instance_exec
method_missing
singleton_method_added
singleton_method_removed
singleton_method_undefined
!~
<=>
==
===
=~
_dump
class
clone
define_singleton_method
display
enum_for
eql?
equal?
extend
freeze
frozen?
hash
initialize
initialize_copy
inspect
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
itself
marshal_dump
marshal_load
method
methods
nil?
object_id
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
psych_to_yaml
public_method
public_methods
public_send
remove_instance_variable
respond_to?
respond_to_missing?
send
singleton_class
singleton_method
singleton_methods
taint
tainted?
tap
to_a
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_s
to_str
trust
untaint
untrust
untrusted?
yield_self
.yaml_tag
::ARGF
::ARGV
::DATA
::ENV
::FALSE
::NIL
::RUBY_COPYRIGHT
::RUBY_DESCRIPTION
::RUBY_ENGINE
::RUBY_ENGINE_VERSION
::RUBY_PATCHLEVEL
::RUBY_PLATFORM
::RUBY_RELEASE_DATE
::RUBY_REVISION
::RUBY_VERSION
::SCRIPT_LINES__
::STDERR
::STDIN
::STDOUT
::TOPLEVEL_BINDING
::TRUE