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.
361 362 363 364 |
# File 'lib/prettyprint.rb', line 361 def initialize(output, maxwidth=nil, newline=nil) @output = output @first = [true] end |
Instance Method Details
#breakable(sep = ' ', width = nil) ⇒ Object
370 371 372 |
# File 'lib/prettyprint.rb', line 370 def breakable(sep=' ', width=nil) @output << sep end |
#first? ⇒ Boolean
389 390 391 392 393 |
# File 'lib/prettyprint.rb', line 389 def first? result = @first[-1] @first[-1] = false result end |
#flush ⇒ Object
386 387 |
# File 'lib/prettyprint.rb', line 386 def flush end |
#group(indent = nil, open_obj = '', close_obj = '', open_width = nil, close_width = nil) ⇒ Object
378 379 380 381 382 383 384 |
# File 'lib/prettyprint.rb', line 378 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
374 375 376 |
# File 'lib/prettyprint.rb', line 374 def nest(indent) yield end |
#text(obj, width = nil) ⇒ Object
366 367 368 |
# File 'lib/prettyprint.rb', line 366 def text(obj, width=nil) @output << obj end |