Class: Symbolic::Constant

Inherits:
Object
  • Object
show all
Includes:
Symbolic
Defined in:
lib/symbolic/constant.rb

Constant Summary

Constants included from Symbolic

OPERATIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Symbolic

#*, #**, #+, #+@, #-, #-@, #/, #coerce, #factorial, #inspect, #operations, #taylor, #to_s

Constructor Details

#initialize(value, name = nil) ⇒ Constant

Create a new Symbolic::Variable, with optional name, value and proc



7
8
9
10
# File 'lib/symbolic/constant.rb', line 7

def initialize(value , name = nil)
  @name, @value = name, value
  @name = @name.to_s if @name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/symbolic/constant.rb', line 4

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/symbolic/constant.rb', line 4

def value
  @value
end

Instance Method Details

#diff(wrt) ⇒ Object



19
20
21
# File 'lib/symbolic/constant.rb', line 19

def diff(wrt)
  0
end

#subs(to_replace, replacement = nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/symbolic/constant.rb', line 11

def subs(to_replace, replacement=nil)
  if replacement == nil and to_replace.is_a?(Hash)
	super(to_replace)
  else
	return replacement if self == to_replace
	self
  end
end

#variablesObject

yeah, it’s not a variable, but it acts like one as far as value is concerned



23
24
25
# File 'lib/symbolic/constant.rb', line 23

def variables
  [self]
end