Sha256: dec96a75a12320bae3bc6d1573f2c4be4baf48fb0b4598537c1b6282d248819a

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

module Veritas
  class Function

    # A mixin for functions with directly compared operands
    module Comparable
      include Immutable

      # Hook called when module is included
      #
      # @param [Module] descendant
      #   the module or class including Comparable
      #
      # @return [self]
      #
      # @api private
      def self.included(descendant)
        descendant.extend ClassMethods
        self
      end

      # Return a string representing the function
      #
      # @example
      #   function.inspect  # (String representation of a Function)
      #
      # @return [String]
      #
      # @api public
      def inspect
        "(#{left.inspect} #{self.class.operation} #{right.inspect})"
      end

      module ClassMethods

        # Evaluate the values using the ruby operation
        #
        # @example
        #   function.call(left, right)  # => true or false
        #
        # @param [Object] left
        # @param [Object] right
        #
        # @return [Object]
        #
        # @api public
        def call(left, right)
          left.send(operation, right)
        end

      end # module Classmethods
    end # class Predicate
  end # class Function
end # module Veritas

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
veritas-0.0.4 lib/veritas/function/comparable.rb