Class: CompSci::KeyNode

Inherits:
Node
  • Object
show all
Defined in:
lib/compsci/node.rb

Overview

adds a key to Node; often the key is used to place the node in the tree, independent of the value; e.g. key=priority, value=process_id

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #value

Instance Method Summary collapse

Methods inherited from Node

#inspect, #set_child

Constructor Details

#initialize(val, key: nil, children: []) ⇒ KeyNode

Returns a new instance of KeyNode.



41
42
43
44
# File 'lib/compsci/node.rb', line 41

def initialize(val, key: nil, children: [])
  @key = key
  super(val, children: children)
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



39
40
41
# File 'lib/compsci/node.rb', line 39

def key
  @key
end

Instance Method Details

#to_sObject



46
47
48
# File 'lib/compsci/node.rb', line 46

def to_s
  [key, value].join(':')
end