Class: AbstractMapper::Rules::Sole Abstract

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

Overview

This class is abstract.

The abstract class that describes the rule to be applied to sole nodes.

The subclass should implement two instance methods:

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

  • ‘#optimize` that should return the optimized node

Examples:

class RemoveEmptyList < AbstractMapper::Rules::Sole
  def optimize?
    node.is_a?(List) && node.empty?
  end

  def optimize
  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

#nodeAbstractMapper::AST::Node (readonly)

Returns The node to be optimized.

Returns:



40
41
42
# File 'lib/abstract_mapper/rules/sole.rb', line 40

def node
  @node
end

Class Method Details

.initialize(node) ⇒ Object



51
52
53
54
# File 'lib/abstract_mapper/rules/sole.rb', line 51

def initialize(node)
  @node = node
  super
end

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

Creates a rule applied to the sole node



# File 'lib/abstract_mapper/rules/sole.rb', line 42