Class: PrettyPrint::SingleLine
- Inherits:
-
Object
- Object
- PrettyPrint::SingleLine
- Defined in:
- lib/prettyprint.rb
Instance Method Summary collapse
- #breakable(sep = ' ', width = nil) ⇒ Object
- #first? ⇒ Boolean
- #flush ⇒ Object
- #group(indent = nil, open_obj = '', close_obj = '', open_width = nil, close_width = nil) ⇒ Object
-
#initialize(output, maxwidth = nil, newline = nil) ⇒ SingleLine
constructor
A new instance of SingleLine.
- #nest(indent) ⇒ Object
- #text(obj, width = nil) ⇒ Object
Constructor Details
#initialize(output, maxwidth = nil, newline = nil) ⇒ SingleLine
Returns a new instance of SingleLine.
345 346 347 348 |
# File 'lib/prettyprint.rb', line 345 def initialize(output, maxwidth=nil, newline=nil) @output = output @first = [true] end |
Instance Method Details
#breakable(sep = ' ', width = nil) ⇒ Object
354 355 356 |
# File 'lib/prettyprint.rb', line 354 def breakable(sep=' ', width=nil) @output << sep end |
#first? ⇒ Boolean
373 374 375 376 377 |
# File 'lib/prettyprint.rb', line 373 def first? result = @first[-1] @first[-1] = false result end |
#flush ⇒ Object
370 371 |
# File 'lib/prettyprint.rb', line 370 def flush end |
#group(indent = nil, open_obj = '', close_obj = '', open_width = nil, close_width = nil) ⇒ Object
362 363 364 365 366 367 368 |
# File 'lib/prettyprint.rb', line 362 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
358 359 360 |
# File 'lib/prettyprint.rb', line 358 def nest(indent) yield end |
#text(obj, width = nil) ⇒ Object
350 351 352 |
# File 'lib/prettyprint.rb', line 350 def text(obj, width=nil) @output << obj end |