class PrettyPrint::SingleLine
PrettyPrint::SingleLine 由 PrettyPrint.singleline_format 使用。
它被传递,以类似于 PrettyPrint 对象本身,通过响应
但输出没有换行。
Public Class Methods
Source
# File lib/prettyprint.rb, line 506 def initialize(output, maxwidth=nil, newline=nil) @output = output @first = [true] end
创建一个 PrettyPrint::SingleLine 对象。
参数
-
output- 用于存储渲染文本的String(或类似对象)。需要响应 ‘<<’。 -
maxwidth- 参数位置,为了兼容性而在此。This argument is a noop.
-
newline- 参数位置,为了兼容性而在此。This argument is a noop.
Public Instance Methods
Source
# File lib/prettyprint.rb, line 521 def breakable(sep=' ', width=nil) @output << sep end
将 sep 追加到要输出的文本中。默认为 ‘ ’。
width 参数是为了兼容性而在此。这是一个 noop 参数。
Source
# File lib/prettyprint.rb, line 553 def first? result = @first[-1] @first[-1] = false result end
这用作一个谓词,应该首先调用。
Source
# File lib/prettyprint.rb, line 540 def group(indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil) @first.push true @output << open_obj yield @output << close_obj @first.pop end
打开一个用于分组要进行漂亮打印的对象的块。
参数
-
indent- noop 参数。为了兼容性而存在。 -
open_obj- 在块之前追加的文本。默认为 ”。 -
close_obj- 在块之后追加的文本。默认为 ”。 -
open_width- noop 参数。为了兼容性而存在。 -
close_width- noop 参数。为了兼容性而存在。
Source
# File lib/prettyprint.rb, line 514 def text(obj, width=nil) @output << obj end
将 obj 添加到要输出的文本中。
width 参数是为了兼容性而在此。这是一个 noop 参数。