class AbstractMapper::Optimizer
Optimizes the immutable abstract syntax tree (AST
) using comfigurable collection of applicable rules.
@api private
Attributes
rules[R]
@!attribute [r] rules
@return [AbstractMapper::Rules]
The collection of applicable optimization rules
Public Class Methods
new(rules)
click to toggle source
@private
# File lib/abstract_mapper/optimizer.rb, line 29 def initialize(rules) @rules = rules IceNine.deep_freeze(self) end
Public Instance Methods
update(tree)
click to toggle source
Recursively optimizes the AST
from root to leafs
@param [AbstractMapper::Branch] tree
@return [AbstractMapper::Branch]
# File lib/abstract_mapper/optimizer.rb, line 40 def update(tree) return tree unless tree.is_a? AST::Branch new_tree = tree.update { rules[tree] } new_tree.update { new_tree.map(&method(:update)) } end