Class: Compo::HashComposite

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Composite
Defined in:
lib/compo/hash_composite.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

HashBranch

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Composite

#add, #get_child, #remove, #remove_id

Constructor Details

#initializeHashComposite

Initialises a HashComposite

Examples:

Initializes a HashComposite.

comp = HashComposite.new


19
20
21
# File 'lib/compo/hash_composite.rb', line 19

def initialize
  @children = {}
end

Instance Attribute Details

#childrenHash (readonly)

Returns the HashComposite’s children, as a Hash

Examples:

Gets the children of an empty HashComposite.

comp.children
#=> {}

Gets the children of a populated HashComposite.

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

Returns:

  • (Hash)

    The Hash mapping the IDs of children to their values.



34
35
36
# File 'lib/compo/hash_composite.rb', line 34

def children
  @children
end