Class: TreeThinking::BinaryTree

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

Defined Under Namespace

Classes: Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil) ⇒ BinaryTree

Returns a new instance of BinaryTree.



8
9
10
# File 'lib/tree_thinking/binary_tree.rb', line 8

def initialize(name: nil)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/tree_thinking/binary_tree.rb', line 3

def name
  @name
end

#treeObject

Returns the value of attribute tree.



4
5
6
# File 'lib/tree_thinking/binary_tree.rb', line 4

def tree
  @tree
end

Instance Method Details

#call(answer_vector) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/tree_thinking/binary_tree.rb', line 12

def call(answer_vector)
  node = self.tree

  while node.probablity.nil? do
    node = node.results.fetch(decision(node, answer_vector))
  end

  node.probablity
end