Sha256: 52231f6f3f0d95bbb218b3a2ee4db50764125d9e47779bdb3154564e678d7125

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

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.3 lib/veritas/support/operation/unary.rb
veritas-0.0.2 lib/veritas/support/operation/unary.rb