PrettyPrint::SingleLine

class PrettyPrint::SingleLine

Parent:
Object

PrettyPrint::SingleLine is used by PrettyPrint.singleline_format

It is passed to be similar to a PrettyPrint object itself, by responding to:

but instead, the output has no line breaks

Public Class Methods

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

Create a PrettyPrint::SingleLine object

Arguments:

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

  • maxwidth - Argument position expected to be here for compatibility.

    This argument is a noop.
  • newline - Argument position expected to be here for compatibility.

    This argument is a noop.
# File lib/prettyprint.rb, line 501
def initialize(output, maxwidth=nil, newline=nil)
  @output = output
  @first = [true]
end

Public Instance Methods

breakable(sep=' ', width=nil) Show source

Appends sep to the text to be output. By default sep is ' '

width argument is here for compatibility. It is a noop argument.

# File lib/prettyprint.rb, line 516
def breakable(sep=' ', width=nil)
  @output << sep
end
first?() Show source

This is used as a predicate, and ought to be called first.

# File lib/prettyprint.rb, line 548
def first?
  result = @first[-1]
  @first[-1] = false
  result
end
group(indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil) { || ... } Show source

Opens a block for grouping objects to be pretty printed.

Arguments:

  • indent - noop argument. Present for compatibility.

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

  • close_obj - text appended after the &blok. Default is ''

  • open_width - noop argument. Present for compatibility.

  • close_width - noop argument. Present for compatibility.

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

Add obj to the text to be output.

width argument is here for compatibility. It is a noop argument.

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

Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部