Class: PrettyPrint::Breakable

Inherits:
Object
  • Object
show all
Defined in:
lib/prettyprint.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Breakable) initialize(sep, width, q)

A new instance of Breakable



260
261
262
263
264
265
266
267
# File 'lib/prettyprint.rb', line 260

def initialize(sep, width, q)
  @obj = sep
  @width = width
  @pp = q
  @indent = q.indent
  @group = q.current_group
  @group.breakables.push self
end

Instance Attribute Details

- (Object) indent (readonly)

Returns the value of attribute indent



268
269
270
# File 'lib/prettyprint.rb', line 268

def indent
  @indent
end

- (Object) obj (readonly)

Returns the value of attribute obj



268
269
270
# File 'lib/prettyprint.rb', line 268

def obj
  @obj
end

- (Object) width (readonly)

Returns the value of attribute width



268
269
270
# File 'lib/prettyprint.rb', line 268

def width
  @width
end

Instance Method Details

- (Object) output(out, output_width)



270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/prettyprint.rb', line 270

def output(out, output_width)
  @group.breakables.shift
  if @group.break?
    out << @pp.newline
    out << @pp.genspace.call(@indent)
    @indent
  else
    @pp.group_queue.delete @group if @group.breakables.empty?
    out << @obj
    output_width + @width
  end
end