Sha256: d1899e9b30339bee4bd29c768af9ed3dd792f3a89a966fa2a28dd1702d93de52

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8

module Veritas
  class Function
    class Numeric

      # A class representing a unary minus function
      class UnaryMinus < Numeric
        include Unary

        # Return the value subtracted from 0
        #
        # @example
        #   negated_value = UnaryMinus.call(value)
        #
        # @param [Numeric] value
        #
        # @return [Numeric]
        #
        # @api public
        def self.call(value)
          -value
        end

        # Return the inverse function class
        #
        # @example
        #   UnaryMinus.inverse  # => UnaryPlus
        #
        # @return [Class<UnaryPlus>]
        #
        # @api public
        def self.inverse
          UnaryPlus
        end

        # Return a string representing the unary minus function
        #
        # @example
        #   unary_minus.inspect  # => "-1"
        #
        # @return [String]
        #
        # @api public
        def inspect
          "-(#{operand.inspect})"
        end

        module Methods
          extend Aliasable

          inheritable_alias(:-@ => :unary_minus)

          # Return a unary minus function
          #
          # @example
          #   unary_minus = attribute.unary_minus
          #
          # @return [UnaryMinus]
          #
          # @api public
          def unary_minus
            UnaryMinus.new(self)
          end

        end # module Methods

        Attribute::Numeric.class_eval { include Methods }
        Numeric.class_eval            { include Methods }

      end # class UnaryMinus
    end # class Numeric
  end # class Function
end # module Veritas

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
veritas-0.0.6 lib/veritas/function/numeric/unary_minus.rb
veritas-0.0.5 lib/veritas/function/numeric/unary_minus.rb
veritas-0.0.4 lib/veritas/function/numeric/unary_minus.rb