Class: PrettyPrint::Breakable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sep, width, q) ⇒ Breakable

Returns a new instance of Breakable.



260
261
262
263
264
265
266
267
# File 'lib/project/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

#indentObject (readonly)

Returns the value of attribute indent.



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

def indent
  @indent
end

#objObject (readonly)

Returns the value of attribute obj.



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

def obj
  @obj
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#output(out, output_width) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/project/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