123456789_123456789_123456789_123456789_123456789_

Class: PrettyPrint::SingleLine

Relationships & Source Files
Inherits: Object
Defined in: lib/prettyprint.rb

Overview

SingleLine is used by singleline_format

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

but instead, the output has no line breaks

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(output, maxwidth = nil, newline = nil) ⇒ SingleLine

Create a SingleLine object

Arguments:

  • PrettyPrint#output - String (or similar) to store rendered text. Needs to respond to ‘<<’

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

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

    This argument is a noop.
[ GitHub ]

  
# File 'lib/prettyprint.rb', line 505

def initialize(output, maxwidth=nil, newline=nil)
  @output = output
  @first = [true]
end

Instance Attribute Details

#first?Boolean (readonly)

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

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 552

def first?
  result = @first[-1]
  @first[-1] = false
  result
end

Instance Method Details

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

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

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

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 520

def breakable(sep=' ', width=nil)
  @output << sep
end

#flush

This method is for internal use only.

Method present for compatibility, but is a noop

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 548

def flush # :nodoc:
end

#group(indent = nil, open_obj = '', close_obj = '', open_width = nil, close_width = nil)

Opens a block for grouping objects to be pretty printed.

Arguments:

  • PrettyPrint#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.

[ GitHub ]

  
# 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

#nest(indent)

This method is for internal use only.

Takes PrettyPrint#indent arg, but does nothing with it.

Yields to a block.

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 527

def nest(indent) # :nodoc:
  yield
end

#text(obj, width = nil)

Add obj to the text to be output.

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

[ GitHub ]

  
# File 'lib/prettyprint.rb', line 513

def text(obj, width=nil)
  @output << obj
end