Method: Quantity#-

Defined in:
lib/quantity.rb

#-(other) ⇒ Quantity

Subtraction. Subtract a quantity from another of the same type. They do not need to share units.

Parameters:

Returns:



147
148
149
150
151
152
153
154
155
# File 'lib/quantity.rb', line 147

def -(other)
  if (other.is_a?(Numeric))
    Quantity.new(@value - other, @unit)
  elsif(other.is_a?(Quantity) && @unit.dimension == other.unit.dimension)
    Quantity.new({:unit => @unit,:reference_value => @reference_value - other.reference_value})
  else
    raise ArgumentError, "Cannot subtract #{other} from #{self}"
  end
end