Class: PrettyPrint::SingleLine

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

Direct Known Subclasses

PP::SingleLine

Instance Method Summary collapse

Constructor Details

#initialize(output, maxwidth = nil, newline = nil) ⇒ SingleLine

Returns a new instance of SingleLine.



343
344
345
346
# File 'lib/project/prettyprint.rb', line 343

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

Instance Method Details

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



352
353
354
# File 'lib/project/prettyprint.rb', line 352

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

#first?Boolean

Returns:

  • (Boolean)


371
372
373
374
375
# File 'lib/project/prettyprint.rb', line 371

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

#flushObject



368
369
# File 'lib/project/prettyprint.rb', line 368

def flush
end

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



360
361
362
363
364
365
366
# File 'lib/project/prettyprint.rb', line 360

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) ⇒ Object



356
357
358
# File 'lib/project/prettyprint.rb', line 356

def nest(indent)
  yield
end

#text(obj, width = nil) ⇒ Object



348
349
350
# File 'lib/project/prettyprint.rb', line 348

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