Class: Symbolic::Variable
- Inherits:
-
Object
- Object
- Symbolic::Variable
- Includes:
- Symbolic
- Defined in:
- lib/symbolic/variable.rb
Overview
This class is used to create symbolic variables.
Symbolic variables presented by name and value.
Name is neccessary for printing meaningful symbolic expressions.
Value is neccesary for calculation of symbolic expressions.
If value isn't set for variable, but there is an associated proc, then value is taken from evaluating the proc.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#proc ⇒ Object
Returns the value of attribute proc.
- #value ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}, &proc) ⇒ Variable
constructor
A new instance of Variable.
- #to_s ⇒ Object
- #variables ⇒ Object
Methods included from Symbolic
#*, #**, #+, #+@, #-, #-@, #/, #coerce, #inspect, #operations
Constructor Details
#initialize(options = {}, &proc) ⇒ Variable
Returns a new instance of Variable.
14 15 16 17 18 |
# File 'lib/symbolic/variable.rb', line 14 def initialize(={}, &proc) @name, @value = .values_at(:name, :value) @name = @name.to_s if @name @proc = proc end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/symbolic/variable.rb', line 11 def name @name end |
#proc ⇒ Object
Returns the value of attribute proc.
11 12 13 |
# File 'lib/symbolic/variable.rb', line 11 def proc @proc end |
#value ⇒ Object
20 21 22 |
# File 'lib/symbolic/variable.rb', line 20 def value @value || @proc && @proc.call.value end |
Instance Method Details
#to_s ⇒ Object
24 25 26 |
# File 'lib/symbolic/variable.rb', line 24 def to_s @name || 'unnamed_variable' end |
#variables ⇒ Object
28 29 30 |
# File 'lib/symbolic/variable.rb', line 28 def variables [self] end |