Sha256: 5d0a7cab882d496cabf71995e92db5a99d1de018c208df7a289d2174dcd4c322

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

# encoding: utf-8

module Veritas
  module Operation
    module Binary
      include Immutable

      # The left operand for the operation
      #
      # @example
      #   left = binary.left
      #
      # @return [Object]
      #
      # @api public
      attr_reader :left

      # The right operand for the operation
      #
      # @example
      #   right = binary.right
      #
      # @return [Object]
      #
      # @api public
      attr_reader :right

      # Initialize Binary Operation
      #
      # @param [Object] left
      #   the left operand for the operation
      # @param [Object] right
      #   the right operand for the operation
      #
      # @return [undefined]
      #
      # @api private
      def initialize(left, right)
        @left  = Immutable.freeze_object(left)
        @right = Immutable.freeze_object(right)
      end

      # Compare the operation with the other operation for equality
      #
      # @example
      #   binary.eql?(other)  # => true or false
      #
      # @param [Object] other
      #
      # @return [Boolean]
      #
      # @api public
      def eql?(other)
        instance_of?(other.class) &&
        left.eql?(other.left)     &&
        right.eql?(other.right)
      end

      # Return the hash of the left and right operands
      #
      # @example
      #   hash = binary.hash
      #
      # @return [Fixnum]
      #
      # @api public
      def hash
        self.class.hash ^ left.hash ^ right.hash
      end

      memoize :hash

    end # module Binary
  end # module Operation
end # module Veritas

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
veritas-0.0.5 lib/veritas/support/operation/binary.rb
veritas-0.0.4 lib/veritas/support/operation/binary.rb