Module: Axiom::Function::Unary

Extended by:
Callable
Includes:
Operation::Unary
Included in:
Connective::Negation, Numeric::Absolute, Numeric::SquareRoot, Numeric::UnaryMinus, Numeric::UnaryPlus, String::Length
Defined in:
lib/axiom/function/unary.rb

Overview

Mixin for unary functions

Defined Under Namespace

Modules: Callable, Invertible

Instance Attribute Summary

Attributes included from Operation::Unary

#operand

Instance Method Summary collapse

Methods included from Callable

included

Methods included from Operation::Unary

#initialize

Instance Method Details

#call(tuple) ⇒ Boolean

Evaluate the unary connective using the tuple

Examples:

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

Parameters:

  • tuple (Tuple)

    the tuple to pass to operand#call

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/axiom/function/unary.rb', line 57

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

#rename(aliases) ⇒ self, Unary

TODO:

handle case where operand is a literal

Rename the contained attributes with the provided aliases

Examples:

renamed = unary.rename(aliases)

Parameters:

Returns:

  • (self)

    if the operand is not renamed

  • (Unary)

    if the operand is renamed



78
79
80
81
82
83
84
85
86
87
# File 'lib/axiom/function/unary.rb', line 78

def rename(aliases)
  util            = self.class
  renamed_operand = util.rename_attributes(operand, aliases)

  if operand.equal?(renamed_operand)
    self
  else
    util.new(renamed_operand)
  end
end

#typeClass<Types::Numeric>

Return the type returned from #call

Examples:

type = unary.type  # => Axiom::Types::Numeric

Returns:

  • (Class<Types::Numeric>)


97
98
99
# File 'lib/axiom/function/unary.rb', line 97

def type
  Attribute.infer_type(operand)
end