Module: Jumoku::Strategies

Defined in:
lib/jumoku/strategies.rb,
lib/jumoku/strategies/edge_labeling.rb,
lib/jumoku/strategies/edge_labeling/simple.rb

Overview

Strategies are decorators implemented as mixins which taint a tree object with new or extended features. For instance, the ‘SimpleEdgeLabeling` strategy alters the way new nodes and branches are added to a tree, enforcing labeling of edges with increasing integers, `Binary` enforces a tree to grow as a binary tree, etc.

It is easy to develop your own decorators and ‘use` them.

Defined Under Namespace

Modules: EdgeLabelingBackend, SimpleEdgeLabeling

Instance Method Summary collapse

Instance Method Details

#use(strategy) ⇒ Object Also known as: strategy

Activate a strategy.

Parameters:

  • strategy (#to_s, Module)

    strategy’s name, either as a module namespace (like ‘Strategies::SimpleEdgeLabeling`) or a symbol (like `:simple_edge_labeling`)



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jumoku/strategies.rb', line 17

def use(strategy)
  strategy = catch(:unknown_strategy) do
    begin
      if strategy.is_a?(Symbol) || strategy.is_a?(String)
        strategy = Strategies.const_get(strategy.to_s.constantize)
      end
    rescue NameError
      throw :unknown_strategy, nil
    end
    strategy
  end
  extend strategy unless strategy.nil?
end