Class: PrettyPrint::Group

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

Overview

The Group class is used for making indentation easier.

While this class does neither the breaking into newlines nor indentation, it is used in a stack (as well as a queue) within PrettyPrint, to group objects.

For information on using groups, see PrettyPrint#group

This class is intended for internal use of the PrettyPrint buffers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth) ⇒ Group

Create a Group object

Arguments:

  • depth - this group’s relation to previous groups



419
420
421
422
423
# File 'lib/prettyprint.rb', line 419

def initialize(depth)
  @depth = depth
  @breakables = []
  @break = false
end

Instance Attribute Details

#breakablesObject (readonly)

Array to hold the Breakable objects for this Group



429
430
431
# File 'lib/prettyprint.rb', line 429

def breakables
  @breakables
end

#depthObject (readonly)

This group’s relation to previous groups



426
427
428
# File 'lib/prettyprint.rb', line 426

def depth
  @depth
end

Instance Method Details

#breakObject

Makes a break for this Group, and returns true



432
433
434
# File 'lib/prettyprint.rb', line 432

def break
  @break = true
end

#break?Boolean

Boolean of whether this Group has made a break

Returns:

  • (Boolean)


437
438
439
# File 'lib/prettyprint.rb', line 437

def break?
  @break
end

#first?Boolean

Boolean of whether this Group has been queried for being first

This is used as a predicate, and ought to be called first.

Returns:

  • (Boolean)


444
445
446
447
448
449
450
451
# File 'lib/prettyprint.rb', line 444

def first?
  if defined? @first
    false
  else
    @first = false
    true
  end
end