Class: Unknown

Inherits:
BaseVariable show all
Defined in:
lib/core/variable/Unknown.rb

Overview

TODO This is not strickly a Variable - it is a data type of it’s own

Instance Attribute Summary

Attributes inherited from BaseVariable

#instance_variable, #uniq_id_history, #value, #variable_id

Attributes included from Variable

#scope_id, #uniq_id

Instance Method Summary collapse

Methods inherited from BaseVariable

#destructive_instance_calls, #find_actual_variable, #instance_calls, reset_global_id, #returning_instance_calls, #write, #write_with_uniq_id

Methods included from Variable

#increament_uniq_id!, #meets_requirements?, reset_global_id, variable_id

Methods included from VariableIncluded

#find_actual_variable, #variable

Methods inherited from Array

#cauldron_method_calls, #contains?, #select_all, #to_intrinsic, #to_literal, #write

Constructor Details

#initialize(*requirements) ⇒ Unknown

TODO I think requirements here can be dropped



8
9
10
# File 'lib/core/variable/Unknown.rb', line 8

def initialize(*requirements)
  super(*requirements)
end

Instance Method Details

#classify(value) ⇒ Object

Returns a typed version of the variable with the correct variable id. This occurs when an Unknown variable is used in a statement and its value can be determined.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/core/variable/Unknown.rb', line 16

def classify(value)
  case value.class.to_s
    when 'String'
      var = StringVariable.new(value)
      var.variable_id = variable_id
      return var
    when 'Fixnum'
      var = FixnumVariable.new(value)
      var.variable_id = variable_id
      return var
  else
    raise StandardError.new('Unknown data type '+value.class.to_s)
  end
end

#copyObject

TODO Should ‘Unknown’ have a variable id



32
33
34
35
36
# File 'lib/core/variable/Unknown.rb', line 32

def copy  
  result = self.class.new(*self) {{:variable_id => variable_id,:uniq_id=>@uniq_id,:uniq_id_history=>@uniq_id_history.copy}}
  result.instance_variable = @instance_variable
  return result
end

#copy_contextual_variableObject

Returns a copy of the variable, this method exists in the instance call class. It avoids distinguishing the two.

Since variale is lowest level context doesn’t matter.



73
74
75
# File 'lib/core/variable/Unknown.rb', line 73

def copy_contextual_variable
  return copy
end

#describe(tab = 0, context = self) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/core/variable/Unknown.rb', line 39

def describe(tab=0,context=self)
  
  # Create a temporay copy of the variable
  copied_var = self.copy

  unless context == self
    
    # Return a duplicate variable with the requirements in the context indicated
    copied_var = context.contextual_variable(copied_var.variable_id)
    
  end
  
  # Print the name of the variable
  line = ''    
  line += write
  
  # Print out each of the requirements
  copied_var.each do |x|        
    desc = x.describe(context)
    desc.each_line do |l|
      line += "\t"+l
    end      
    line += "\n" unless x == copied_var.last      
  end
  line += "\n"
  
  return line
  
end

#equivalent?(to) ⇒ Boolean

Unknown variables are evaluated are runtime so as along as it is a variable it is probably fine.

Returns:



97
98
99
100
# File 'lib/core/variable/Unknown.rb', line 97

def equivalent?(to)
  return true if to.kind_of?(BaseVariable)
  return false
end

#realised?Boolean

Returns:



81
82
83
# File 'lib/core/variable/Unknown.rb', line 81

def realised?
  return false
end

#to_declarationObject



85
86
87
# File 'lib/core/variable/Unknown.rb', line 85

def to_declaration
  return VariableDeclaration.new('Unknown')
end

#to_literal_stringObject



77
78
79
# File 'lib/core/variable/Unknown.rb', line 77

def to_literal_string
  return 'var'  
end

#to_var(id = nil, uniq_id = nil) ⇒ Object



89
90
91
92
# File 'lib/core/variable/Unknown.rb', line 89

def to_var(id=nil,uniq_id=nil)
  StandardLogger.instance.warning('"Unknown" is NOT a variable - it is a data type')
  return UnknownVariable.new(self) {{:variable_id => id,:uniq_id=>uniq_id}}
end