Class: Fear::Extractor::ArrayMatcher Private

Inherits:
Matcher
  • Object
show all
Defined in:
lib/fear/extractor/array_matcher.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Recursive array matcher. Match against its head and tail

Constant Summary

Constants inherited from Matcher

Matcher::EMPTY_ARRAY, Matcher::EMPTY_HASH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#and, #call, #call_or_else, #initialize

Constructor Details

This class inherits a constructor from Fear::Extractor::Matcher

Instance Attribute Details

#headArrayHeadMatcher


13
14
15
16
17
# File 'lib/fear/extractor/array_matcher.rb', line 13

def defined_at?(other)
  if other.is_a?(Array)
    head.defined_at?(other) && tail.defined_at?(other.slice(1..-1))
  end
end

#tailArrayMatcher | EmptyListMatcher


13
14
15
16
17
# File 'lib/fear/extractor/array_matcher.rb', line 13

def defined_at?(other)
  if other.is_a?(Array)
    head.defined_at?(other) && tail.defined_at?(other.slice(1..-1))
  end
end

Instance Method Details

#bindings(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


19
20
21
22
23
24
25
# File 'lib/fear/extractor/array_matcher.rb', line 19

def bindings(other)
  if head.is_a?(ArraySplatMatcher)
    head.bindings(other)
  else
    head.bindings(other).merge(tail.bindings(other.slice(1..-1)))
  end
end

#defined_at?(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


13
14
15
16
17
# File 'lib/fear/extractor/array_matcher.rb', line 13

def defined_at?(other)
  if other.is_a?(Array)
    head.defined_at?(other) && tail.defined_at?(other.slice(1..-1))
  end
end

#failure_reason(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fear/extractor/array_matcher.rb', line 27

def failure_reason(other)
  if other.is_a?(Array)
    if head.defined_at?(other)
      tail.failure_reason(other.slice(1..-1))
    else
      head.failure_reason(other)
    end
  else
    super
  end
end