Sha256: ee11826d68d46e4ec12752980586cd868cb9d4fdd9ee7e4d4383d3ad5e0ae3b2

Contents?: true

Size: 579 Bytes

Versions: 3

Compression:

Stored size: 579 Bytes

Contents

module Dydx
  module Algebra
    module Operator
      module Parts
        module Interface
          %w(+ - * / ^).map(&:to_sym).each do |operator|
            define_method(operator) do |x|
              x = ::Set::Num.new(x) if x.is_a?(Fixnum)
              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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dydx-0.0.7 lib/dydx/algebra/operator/parts/interface.rb
dydx-0.0.6 lib/dydx/algebra/operator/parts/interface.rb
dydx-0.0.5 lib/dydx/algebra/operator/parts/interface.rb