Class: Symbolic::Variable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Symbolic

#*, #**, #+, #+@, #-, #-@, #/, #coerce, #operations

Constructor Details

#initialize(options = {}, &proc) ⇒ Variable

Returns a new instance of Variable.



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

def initialize(options={}, &proc)
  @name, @value = options.values_at(:name, :value)
  @name = @name.to_s if @name
  @proc = proc
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#procObject

Returns the value of attribute proc.



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

def proc
  @proc
end

#valueObject



13
14
15
# File 'lib/symbolic/variable.rb', line 13

def value
  @value || @proc && @proc.call
end

Instance Method Details

#detailed_operationsObject



29
30
31
# File 'lib/symbolic/variable.rb', line 29

def detailed_operations
  Hash.new 0
end

#to_sObject



17
18
19
# File 'lib/symbolic/variable.rb', line 17

def to_s
  @name || 'unnamed_variable'
end

#undefined_variablesObject



25
26
27
# File 'lib/symbolic/variable.rb', line 25

def undefined_variables
  value ? [] : variables
end

#variablesObject



21
22
23
# File 'lib/symbolic/variable.rb', line 21

def variables
  [self]
end