Sha256: 9c703e6b01eec38f216cdfe8ff8949b493b7f4dcc61d0dba8fdbc9f8c32743b1

Contents?: true

Size: 651 Bytes

Versions: 6

Compression:

Stored size: 651 Bytes

Contents

require 'dydx/helper'
require 'dydx/algebra'

module Dydx
  include Algebra
  class Delta
    attr_accessor :var, :function
    def initialize(var, function)
      @var      = var
      @function = function
    end

    def /(delta)
      if var
        eval("$#{var}").differentiate(delta.var)
      elsif delta.function
        delta.function.differentiate(delta.var)
      end
    end
  end

  def method_missing(method, *args, &block)
    method_name = method.to_s
    return super unless (method_name[0] == 'd' && method_name.size <= 2)
    method_name.slice!(0)
    Delta.new(method_name.empty? ? nil : method_name.to_sym, args.first)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dydx-0.0.6 lib/dydx.rb
dydx-0.0.5 lib/dydx.rb
dydx-0.0.4 lib/dydx.rb
dydx-0.0.3 lib/dydx.rb
dydx-0.0.2 lib/dydx.rb
dydx-0.0.1 lib/dydx.rb