Class: Highway::Compiler::Analyze::Tree::Values::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/highway/compiler/analyze/tree/values/base.rb

Overview

This class is a base abstract class for other classes in this module. You should not use it directly.

Direct Known Subclasses

Array, Hash, Primitive

Instance Method Summary collapse

Constructor Details

#initializeBase

Initialize an instance.

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/highway/compiler/analyze/tree/values/base.rb', line 19

def initialize()
  raise NotImplementedError.new("You must not call `#{__method__.to_s}` on `#{self.class.to_s}`.")
end

Instance Method Details

#flatten_segmentsArray<Highway::Compiler::Analyze::Tree::Segments::*>

A flat array of all segments.

Returns:

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/highway/compiler/analyze/tree/values/base.rb', line 26

def flatten_segments
  raise NotImplementedError.new("You must override `#{__method__.to_s}` in `#{self.class.to_s}`.")
end

#select_segments(&block) ⇒ Array<Highway::Compiler::Analyze::Tree::Segments::*>

A flat array of all segments which satisty the given block.

Parameters:

  • &block (Block)

    The selection block.

Returns:



35
36
37
# File 'lib/highway/compiler/analyze/tree/values/base.rb', line 35

def select_segments(&block)
  flatten_segments.select(&block)
end

#select_variable_segments(&block) ⇒ Array<Highway::Compiler::Analyze::Tree::Segments::Variable>

The flat array of variable segments which satisfy the given block.

Parameters:

  • &block (Block)

    The selection block.

Returns:



44
45
46
47
48
49
50
# File 'lib/highway/compiler/analyze/tree/values/base.rb', line 44

def select_variable_segments(&block)
  if block_given?
    select_segments { |s| s.is_a?(Segments::Variable) && block.call(s) }
  else
    select_segments { |s| s.is_a?(Segments::Variable) }
  end
end

#select_variable_segments_with_scope(scope) ⇒ Array<Highway::Compiler::Analyze::Tree::Segments::Variable>

The flat array of variable segments with the given scope.

Parameters:

  • &block (Symbol)

    The lookup scope.

Returns:



57
58
59
# File 'lib/highway/compiler/analyze/tree/values/base.rb', line 57

def select_variable_segments_with_scope(scope)
  select_variable_segments { |s| s.scope == scope }
end