Ruby 2.4

PrettyPrint::SingleLine

class PrettyPrint::SingleLine

父类:对象

PrettyPrint.singleline_format使用PrettyPrint :: SingleLine

它通过类似于PrettyPrint对象本身,通过回应:

  • text

  • breakable

  • nest

  • group

  • flush

  • first?

但相反,输出没有换行符

Public Class Methods

new(output, maxwidth=nil, newline=nil) Show source

创建一个PrettyPrint :: SingleLine对象

参数:

  • output - String (or similar) to store rendered text. Needs to respond to '<<'

  • maxwidth - 参数位置预计在这里兼容。

这个论点是一个noop。

  • newline - 参数位置预计在这里兼容。#file lib / prettyprint.rb,第502行def initialize(output,maxwidth = nil,newline = nil)@output = output @first = [true] endPublic实例方法breakable(sep ='',width =无)显示源追加sep到要输出的文本。默认情况下sep是''width这里的参数是为了兼容性。它是一个noop参数。#file lib / prettyprint.rb,第517行def breakable(sep ='',width = nil)@output << sep第一个结尾?()显示源这用作谓词,并且应该首先调用。#文件lib / prettyprint.rb,第549行def首先?result = @first [-1] @first [-1] = false结束组(indent = nil,open_obj ='',close_obj ='',open_width = nil,close_width = nil)...}显示源打开一个块,用于将对象分组以打印漂亮。参数:

  • indent - 不争论的论点。目前的兼容性。

  • open_obj - text appended before the &blok. Default is ''

  • close_obj - 在&blok后面添加文本。默认值是''

  • open_width - 不争论的论点。目前的兼容性。

  • close_width - 不争论的论点。目前的兼容性。

# File lib/prettyprint.rb, line 536 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

text(obj, width=nil) Show source

添加obj到要输出的文本。

width这里的参数是为了兼容性。这是一个不合理的论点。

# File lib/prettyprint.rb, line 510 def text(obj, width=nil) @output << obj end