Class: Compo::Composites::Hash

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Composite
Defined in:
lib/compo/composites/hash.rb

Overview

Implementation of Composite that stores its children in a Hash.

IDs for items entering a ListComposite may be any permissible hash.

Adding an item at an occupied ID removes the occupant.

Direct Known Subclasses

Branches::Hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Composite

#add, #get_child, #get_child_such_that, #remove, #remove_id

Constructor Details

#initializeHash

Initialises a hash composite

Examples:

Initializes a hash composite.

comp = Compo::Composites::Hash.new


20
21
22
# File 'lib/compo/composites/hash.rb', line 20

def initialize
  @children = {}
end

Instance Attribute Details

#childrenHash (readonly)

Returns the hash composite’s children, as a Hash

Examples:

Gets the children of an empty hash composite.

comp.children
#=> {}

Gets the children of a populated hash composite.

comp.children
#=> {foo: 3, bar: 5}

Returns:

  • (Hash)

    The Hash mapping the IDs of children to their values.



35
36
37
# File 'lib/compo/composites/hash.rb', line 35

def children
  @children
end