Module: Axiom::Function::Binary
- Includes:
- Operation::Binary
- Included in:
- Connective::Conjunction, Connective::Disjunction, Numeric::Addition, Numeric::Division, Numeric::Exponentiation, Numeric::Modulo, Numeric::Multiplication, Numeric::Subtraction, Predicate
- Defined in:
- lib/axiom/function/binary.rb
Overview
Mixin for binary functions
Defined Under Namespace
Modules: Invertible
Instance Attribute Summary
Attributes included from Operation::Binary
Instance Method Summary collapse
-
#call(tuple) ⇒ Boolean
Evaluate the binary function using the tuple.
-
#rename(aliases) ⇒ self, Binary
Rename the contained attributes with the provided aliases.
-
#type ⇒ Class<Types::Numeric>
Return the type returned from #call.
Methods included from Operation::Binary
Instance Method Details
#call(tuple) ⇒ Boolean
Evaluate the binary function using the tuple
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
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 |
#type ⇒ Class<Types::Numeric>
Return the type returned from #call
Find the lowest common ancestor between the types.
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 |