def +(other)
if Unit === other
case
when self.zero? : other.dup
when self =~ other :
raise ArgumentError, "Cannot add two temperatures" if (self.is_temperature? && other.is_temperature?)
if [self, other].any? {|x| x.is_temperature?}
case self.is_temperature?
when true:
Unit.new(:scalar => (self.scalar + other.to(self.temperature_scale).scalar), :numerator => @numerator, :denominator=>@denominator, :signature => @signature)
else
Unit.new(:scalar => (other.scalar + self.to(other.temperature_scale).scalar), :numerator => other.numerator, :denominator=>other.denominator, :signature => other.signature)
end
else
@q ||= ((@@cached_units[self.units].scalar / @@cached_units[self.units].base_scalar) rescue (self.units.unit.to_base.scalar))
Unit.new(:scalar=>(self.base_scalar + other.base_scalar)*@q, :numerator=>@numerator, :denominator=>@denominator, :signature => @signature)
end
else
raise ArgumentError, "Incompatible Units ('#{self}' not compatible with '#{other}')"
end
elsif Time === other
other + self
else
x,y = coerce(other)
y + x
end
end