Method: Quantify::Unit::Base#divide

Defined in:
lib/quantify/unit/base_unit.rb

#divide(other) ⇒ Object Also known as: /

Divide one unit by another. This results in the generation of a compound unit.

In the event that the new unit represents a known unit, the non-compound representation is returned (i.e. of the SI or NonSI class).



459
460
461
462
463
464
465
466
467
468
469
# File 'lib/quantify/unit/base_unit.rb', line 459

def divide(other)
  options = []
  self.instance_of?(Unit::Compound) ? options += @base_units : options << self

  if other.instance_of? Unit::Compound
    options += other.base_units.map { |base| base.index *= -1; base }
  else
    options << CompoundBaseUnit.new(other,-1)
  end
  Unit::Compound.new(*options)
end