Module: Axiom::Function::Binary

Overview

Mixin for binary functions

Defined Under Namespace

Modules: Invertible

Instance Attribute Summary

Attributes included from Operation::Binary

#left, #right

Instance Method Summary collapse

Methods included from Operation::Binary

#initialize

Instance Method Details

#call(tuple) ⇒ Boolean

Evaluate the binary function using the tuple

Examples:

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

Parameters:

  • tuple (Tuple)

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

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/axiom/function/binary.rb', line 21

def call(tuple)
  util = self.class
  util.call(
    util.extract_value(left,  tuple),
    util.extract_value(right, tuple)
  )
end

#rename(aliases) ⇒ self, Binary

TODO:

handle case where left/right are literals

Rename the contained attributes with the provided aliases

Examples:

renamed = binary.rename(aliases)

Parameters:

Returns:

  • (self)

    if the left and right operands are not renamed

  • (Binary)

    if the left or right operand is renamed



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/axiom/function/binary.rb', line 45

def rename(aliases)
  util          = self.class
  renamed_left  = util.rename_attributes(left,  aliases)
  renamed_right = util.rename_attributes(right, aliases)

  if left.equal?(renamed_left) && right.equal?(renamed_right)
    self
  else
    util.new(renamed_left, renamed_right)
  end
end

#typeClass<Types::Numeric>

Return the type returned from #call

Find the lowest common ancestor between the types.

Examples:

type = binary.type  # => Axiom::Types::Object

Returns:

  • (Class<Types::Numeric>)


67
68
69
70
71
72
# File 'lib/axiom/function/binary.rb', line 67

def type
  base = super.singleton_class
  [left, right].map do |operand|
    Attribute.infer_type(operand).ancestors.grep(base)
  end.inject(:&).first
end