lib/quantify/quantity.rb
# Quantities must be of the same dimension in order to operate. If they are
# represented by different units (but represent the same physical quantity)
# the second quantity is converted into the unit belonging to the first unit
# and the addition is completed
#
Quantities must be of the same dimension in order to operate. If they are
represented by different units (but represent the same physical quantity)
the second quantity is converted into the unit belonging to the first unit
and the addition is completed
Quantities must be of the same dimension in order to operate . If they are represented by different units ( but represent the same physical quantity ) the second quantity is converted into the unit belonging to the first unit and the addition is completed
def add_or_subtract!(operator,other)
      if other.is_a? Quantity
        other = other.to(@unit) if other.unit.is_alternative_for?(@unit)
        if @unit.is_equivalent_to? other.unit
          @value = @value.send operator, other.value
          return self
        else
          raise Quantify::Exceptions::InvalidObjectError, "Cannot add or subtract Quantities with different dimensions"
        end
      else
        raise Quantify::Exceptions::InvalidObjectError, "Cannot add or subtract non-Quantity objects"
      end
    end
def add_or_subtract! ( operator , other ) if other . is_a? Quantity other = other . to ( @unit ) if other . unit . is_alternative_for? ( @unit ) if @unit . is_equivalent_to? other . unit @value = @value . send operator , other . value return self else raise Quantify :: Exceptions :: InvalidObjectError , "Cannot add or subtract Quantities with different dimensions" end else raise Quantify :: Exceptions :: InvalidObjectError , "Cannot add or subtract non-Quantity objects" end end
Quantities must be of the same dimension in order to operate.
Quantities must be of the same dimension in order to operate .
operator
<not_specific>
other
<not_specific>