Class: Dydx::Function
- Inherits:
-
Object
- Object
- Dydx::Function
- Defined in:
- lib/dydx/function.rb
Instance Attribute Summary collapse
-
#algebra ⇒ Object
Returns the value of attribute algebra.
-
#vars ⇒ Object
Returns the value of attribute vars.
Instance Method Summary collapse
- #<=(algebra) ⇒ Object
- #==(function) ⇒ Object
- #differentiate(sym = :x) ⇒ Object (also: #d)
- #evalue(nums) ⇒ Object
-
#initialize(*vars) ⇒ Function
constructor
A new instance of Function.
- #to_s ⇒ Object
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
#algebra ⇒ Object
Returns the value of attribute algebra.
3 4 5 |
# File 'lib/dydx/function.rb', line 3 def algebra @algebra end |
#vars ⇒ Object
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_s ⇒ Object
27 28 29 |
# File 'lib/dydx/function.rb', line 27 def to_s algebra.to_s end |