Class: HybridForest::Trees::BinaryNode
- Inherits:
-
Object
- Object
- HybridForest::Trees::BinaryNode
- Defined in:
- lib/hybridforest/trees/nodes/binary_node.rb
Instance Attribute Summary collapse
-
#false_branch ⇒ Object
readonly
Returns the value of attribute false_branch.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
-
#true_branch ⇒ Object
readonly
Returns the value of attribute true_branch.
Instance Method Summary collapse
- #branch_for(instance) ⇒ Object
- #classify(instance) ⇒ Object
-
#initialize(test, true_branch, false_branch) ⇒ BinaryNode
constructor
A new instance of BinaryNode.
- #print_string(spacing = "") ⇒ Object
Constructor Details
#initialize(test, true_branch, false_branch) ⇒ BinaryNode
Returns a new instance of BinaryNode.
8 9 10 11 12 |
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 8 def initialize(test, true_branch, false_branch) @test = test @true_branch = true_branch @false_branch = false_branch end |
Instance Attribute Details
#false_branch ⇒ Object (readonly)
Returns the value of attribute false_branch.
6 7 8 |
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 6 def false_branch @false_branch end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
6 7 8 |
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 6 def test @test end |
#true_branch ⇒ Object (readonly)
Returns the value of attribute true_branch.
6 7 8 |
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 6 def true_branch @true_branch end |
Instance Method Details
#branch_for(instance) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 14 def branch_for(instance) if @test.passed_by? instance @true_branch else @false_branch end end |
#classify(instance) ⇒ Object
22 23 24 |
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 22 def classify(instance) branch_for(instance).classify(instance) end |
#print_string(spacing = "") ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/hybridforest/trees/nodes/binary_node.rb', line 26 def print_string(spacing = "") print spacing puts "#{@test} True" @true_branch.print_string(spacing + " ") print spacing puts "#{@test} False" @false_branch.print_string(spacing + " ") end |