Class: AbstractMapper::Rules::Pair Abstract

Inherits:
Base
  • Object
show all
Defined in:
lib/abstract_mapper/rules/pair.rb

Overview

This class is abstract.

The base class for rules to be applied to pairs of nodes.

The subclass should implement two instance methods:

  • ‘#optimize?` to check if the optimization should be applied to the nodes

  • ‘#optimize` that should return the merged node

Examples:

class MergeConsecutiveLists < AbstractMapper::Rules::Pair
  def optimize?
    left.is_a?(List) & right.is_a?(List)
  end

  def optimize
    List.new { left.entries + right.entries }
  end
end

Instance Attribute Summary collapse

Attributes inherited from Base

#nodes

Class Method Summary collapse

Methods inherited from Base

#call, #initialize, #optimize, #optimize?, transproc

Constructor Details

This class inherits a constructor from AbstractMapper::Rules::Base

Instance Attribute Details

#leftAbstractMapper::AST::Node (readonly)

Returns The left node in the pair.

Returns:



41
42
43
# File 'lib/abstract_mapper/rules/pair.rb', line 41

def left
  @left
end

#nodeAbstractMapper::AST::Node (readonly)

Returns The right node in the pair.

Returns:



41
# File 'lib/abstract_mapper/rules/pair.rb', line 41

attr_reader :left

#rightAbstractMapper::AST::Node (readonly)

Returns The right node in the pair.

Returns:



47
48
49
# File 'lib/abstract_mapper/rules/pair.rb', line 47

def right
  @right
end

Class Method Details

.initialize(left, right) ⇒ Object



58
59
60
61
62
# File 'lib/abstract_mapper/rules/pair.rb', line 58

def initialize(left, right)
  @left  = left
  @right = right
  super
end

.new(node) ⇒ AbstractMapper::Rules::Base

Creates a rule applied to the sole node



# File 'lib/abstract_mapper/rules/pair.rb', line 49