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

Returns:



11
12
13
14
15
# File 'lib/fear/extractor/array_matcher.rb', line 11

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

#tailArrayMatcher | EmptyListMatcher



11
12
13
14
15
# File 'lib/fear/extractor/array_matcher.rb', line 11

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.



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

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.

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/fear/extractor/array_matcher.rb', line 11

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.



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

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