Sha256: b4134b18d9d7f7bae70492ddfa181c47b365e20c1d8295bcc5b562e53fffcae8

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8

module Axiom

  # Abstract base class for logical functions
  class Function
    include AbstractType, Adamantium, Visitable

    abstract_singleton_method :call, :type
    abstract_method :rename

    # Rename the attribute(s) inside the function
    #
    # @param [Function] operand
    #
    # @param [Algebra::Rename::Aliases] aliases
    #
    # @return [Function]
    #
    # @todo simplify once Attribute#rename works the same as Function#rename
    #
    # @api private
    def self.rename_attributes(operand, aliases)
      if operand.respond_to?(:rename) && ! operand.kind_of?(Attribute)
        operand.rename(aliases)
      else
        aliases[operand]
      end
    end

    # Extract the value from the operand or tuple
    #
    # @param [Object, #call] operand
    #   the operand to extract the value from
    # @param [Tuple] tuple
    #   the tuple to pass in to the operand if it responds to #call
    #
    # @return [Object]
    #
    # @api private
    def self.extract_value(operand, tuple)
      operand.respond_to?(:call) ? operand.call(tuple) : operand
    end

    # Return the function type
    #
    # @example
    #   type = function.type  # => Axiom::Types::Object
    #
    # @return [Class<Types::Object>]
    #
    # @api public
    def type
      self.class.type
    end

  end # class Function
end # module Axiom

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axiom-0.1.1 lib/axiom/function.rb