lib/unitwise/unit.rb in unitwise-0.3.0 vs lib/unitwise/unit.rb in unitwise-0.3.1
- old
+ new
@@ -26,12 +26,12 @@
def special?
terms.count == 1 && terms.all?(&:special?)
end
- def functional(x=scalar, direction=1)
- terms.first.functional(x, direction)
+ def functional(x=scalar, forward=true)
+ terms.first.functional(x, forward)
end
def dup
self.class.new(expression)
end
@@ -57,17 +57,23 @@
end
def *(other)
if other.respond_to?(:terms)
self.class.new(terms + other.terms)
+ elsif other.respond_to?(:atom)
+ self.class.new(terms << other)
+ elsif other.is_a?(Numeric)
+ self.class.new(terms.map{ |t| t * other })
else
raise TypeError, "Can't multiply #{inspect} by #{other}."
end
end
def /(other)
if other.respond_to?(:terms)
self.class.new(terms + other.terms.map{ |t| t ** -1})
+ elsif other.respond_to?(:atom)
+ self.class.new(terms << other ** -1)
else
raise TypeError, "Can't divide #{inspect} by #{other}."
end
end
\ No newline at end of file