Class: PrettyPrint::Breakable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sep, width, q) ⇒ Breakable

Returns a new instance of Breakable.



278
279
280
281
282
283
284
285
# File 'lib/prettyprint.rb', line 278

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

#indentObject (readonly)

Returns the value of attribute indent



286
287
288
# File 'lib/prettyprint.rb', line 286

def indent
  @indent
end

#objObject (readonly)

Returns the value of attribute obj



286
287
288
# File 'lib/prettyprint.rb', line 286

def obj
  @obj
end

#widthObject (readonly)

Returns the value of attribute width



286
287
288
# File 'lib/prettyprint.rb', line 286

def width
  @width
end

Instance Method Details

#output(out, output_width) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/prettyprint.rb', line 288

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