lib/dydx/algebra/operator/parts/interface.rb in dydx-0.0.4 vs lib/dydx/algebra/operator/parts/interface.rb in dydx-0.0.5
- old
+ new
@@ -1,13 +1,21 @@
module Dydx
module Algebra
module Operator
module Parts
module Interface
- %w(+ - * / ^).each do |operator|
+ %w(+ - * / ^).map(&:to_sym).each do |operator|
define_method(operator) do |x|
x = ::Set::Num.new(x) if x.is_a?(Fixnum)
- super(x)
+ case operator
+ when :-
+ self + inverse(x, :+)
+ when :/
+ raise ZeroDivisionError if x.is_0?
+ self * inverse(x, :*)
+ else
+ super(x)
+ end
end
end
end
end
end