class PrettyPrint::SingleLine - Documentation for Ruby 4.0
Description: class PrettyPrint::SingleLine: SingleLine is used by PrettyPrint.
Keywords: ruby,class,PrettyPrint::SingleLine

🔍

No recent searches

# class PrettyPrint::SingleLine

`PrettyPrint::SingleLine` is used by `PrettyPrint.singleline_format`

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

- `text`

- `breakable`

- nest

- `group`

- flush

- `first?`

but instead, the output has no line breaks

### Public Class Methods

new (output, maxwidth=nil, newline=nil)
Source

    # File lib/prettyprint.rb, line 506
    def initialize(output, maxwidth=nil, newline=nil)
      @output = output
      @first = [true]
    end

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.

### Public Instance Methods

breakable (sep=' ', width=nil)
Source

    # File lib/prettyprint.rb, line 521
    def breakable(sep=' ', width=nil)
      @output << sep
    end

Appends `sep` to the text to be output. By default `sep` is ‘ ’

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

first? ()
Source

    # File lib/prettyprint.rb, line 553
    def first?
      result = @first[-1]
      @first[-1] = false
      result
    end

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

group (indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil) { || ... }
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

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.

text (obj, width=nil)
Source

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

Add `obj` to the text to be output.

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