Class: Dydx::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/dydx/function.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*vars) ⇒ Function

Returns a new instance of Function.



4
5
6
# File 'lib/dydx/function.rb', line 4

def initialize(*vars)
  @vars = vars
end

Instance Attribute Details

#algebraObject

Returns the value of attribute algebra.



3
4
5
# File 'lib/dydx/function.rb', line 3

def algebra
  @algebra
end

#varsObject

Returns the value of attribute vars.



3
4
5
# File 'lib/dydx/function.rb', line 3

def vars
  @vars
end

Instance Method Details

#<=(algebra) ⇒ Object



8
9
10
11
# File 'lib/dydx/function.rb', line 8

def <=(algebra)
  @algebra = algebra
  self
end

#==(function) ⇒ Object



31
32
33
# File 'lib/dydx/function.rb', line 31

def ==(function)
  to_s == function.to_s
end

#differentiate(sym = :x) ⇒ Object Also known as: d



22
23
24
# File 'lib/dydx/function.rb', line 22

def differentiate(sym = :x)
  @algebra.differentiate(sym)
end

#evalue(nums) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/dydx/function.rb', line 13

def evalue(nums)
  subst_hash = Hash[*[@vars, nums].transpose.flatten]
  begin
    @algebra.subst(subst_hash).to_f
  rescue ArgumentError
    eval(@algebra.subst(subst_hash).to_s)
  end
end

#to_sObject



27
28
29
# File 'lib/dydx/function.rb', line 27

def to_s
  algebra.to_s
end