class PrettyPrint::SingleLine
PrettyPrint::SingleLine 被 PrettyPrint.singleline_format 使用
它被传递时类似于 PrettyPrint 对象本身,通过响应
但相反,输出没有换行符
公共类方法
源代码
# File lib/prettyprint.rb, line 505 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.
公共实例方法
源代码
# File lib/prettyprint.rb, line 520 def breakable(sep=' ', width=nil) @output << sep end
将 sep 附加到要输出的文本。默认情况下,sep 是 ‘ ’
width 参数在这里是为了兼容性。它是一个空操作参数。
源代码
# File lib/prettyprint.rb, line 552 def first? result = @first[-1] @first[-1] = false result end
这用作谓词,应该首先调用。
源代码
# File lib/prettyprint.rb, line 539 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- 空操作参数。为了兼容性而存在。 -
open_obj- &blok 之前的附加文本。默认为“” -
close_obj- &blok 之后的附加文本。默认为“” -
open_width- 空操作参数。为了兼容性而存在。 -
close_width- 空操作参数。为了兼容性而存在。
源代码
# File lib/prettyprint.rb, line 513 def text(obj, width=nil) @output << obj end
将 obj 添加到要输出的文本。
width 参数在这里是为了兼容性。它是一个空操作参数。