Sha256: a6087d25642c9703f3c44e8a5aa4268f63323504d58f5e23836695dfbbddf2e7

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

# encoding: utf-8

module Veritas
  module Operation
    module Unary
      include Immutable

      # The operand to the operation
      #
      # @example
      #   operand = unary.operand
      #
      # @return [Object]
      #
      # @api public
      attr_reader :operand

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

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

      # Return the hash of the operand
      #
      # @example
      #   hash = unary.hash
      #
      # @return [Fixnum]
      #
      # @api public
      def hash
        self.class.hash ^ operand.hash
      end

      memoize :hash

    end # module Unary
  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/unary.rb
veritas-0.0.4 lib/veritas/support/operation/unary.rb