Module: Axiom::Function::Predicate::Enumerable

Included in:
Exclusion, Inclusion
Defined in:
lib/axiom/function/predicate/enumerable.rb

Overview

A mixin for predicates matching an enumerable

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.compare_method(enumerable) ⇒ Symbol

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.

Return the method to test the enumerable with

Parameters:

  • enumerable (#cover?, #include?)

Returns:

  • (Symbol)


17
18
19
# File 'lib/axiom/function/predicate/enumerable.rb', line 17

def self.compare_method(enumerable)
  enumerable.respond_to?(:cover?) ? :cover? : :include?
end

Instance Method Details

#call(tuple) ⇒ Boolean

Evaluate the enumerable function using the tuple

Examples:

enumerable.call(tuple)  # => true or false

Parameters:

  • tuple (Tuple)

    the tuple to pass to #call in the left and right operands

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/axiom/function/predicate/enumerable.rb', line 32

def call(tuple)
  util = self.class
  util.call(
    util.extract_value(left, tuple),
    right.map { |entry| util.extract_value(entry, tuple) }
  )
end