Class: StatementVariable
- Inherits:
-
TypeVariable
- Object
- Array
- BaseVariable
- TypeVariable
- StatementVariable
- Defined in:
- lib/core/variable/StatementVariable.rb
Instance Attribute Summary
Attributes inherited from TypeVariable
Attributes inherited from BaseVariable
#instance_variable, #uniq_id_history, #value, #variable_id
Attributes included from Variable
Instance Method Summary collapse
- #copy ⇒ Object
-
#copy_contextual_variable ⇒ Object
Returns a copy of the variable, this method exists in the instance call class.
- #destructive_instance_calls(available = []) ⇒ Object
-
#equivalent?(to) ⇒ Boolean
Compares the passed argument and returns true if it is a unknown variable which is treated as a wild card or a variable with the same value.
-
#initialize(val) ⇒ StatementVariable
constructor
A new instance of StatementVariable.
-
#instance_calls(available = []) ⇒ Object
Returns an array of instance calls the Statement instances can call.
-
#returning_instance_calls(available = []) ⇒ Object
Returns an array of instances calls that return a value and are therefore approriate for declaration statements.
-
#variable_id=(id) ⇒ Object
Only let this method be called from fellow Fixnum classes or Unknowns.
Methods inherited from TypeVariable
#cauldron_method_calls, #describe, #literalisable?, #literalise, #realised?, #to_literal_string
Methods inherited from BaseVariable
#find_actual_variable, #realised?, reset_global_id, #write, #write_with_uniq_id
Methods included from Variable
#increament_uniq_id!, #meets_requirements?, reset_global_id, #to_var, variable_id
Methods included from VariableIncluded
#find_actual_variable, #variable
Methods inherited from Array
#cauldron_method_calls, #contains?, #select_all, #to_declaration, #to_intrinsic, #to_literal, #to_var, #write
Constructor Details
#initialize(val) ⇒ StatementVariable
Returns a new instance of StatementVariable.
3 4 5 |
# File 'lib/core/variable/StatementVariable.rb', line 3 def initialize(val) super(val) end |
Instance Method Details
#copy ⇒ Object
7 8 9 10 11 |
# File 'lib/core/variable/StatementVariable.rb', line 7 def copy copied = self.class.new(@value.copy) {{:variable_id => self.variable_id,:uniq_id=>@uniq_id, :uniq_id_history=>@uniq_id_history.copy}} copied.variable_id = self.variable_id return copied end |
#copy_contextual_variable ⇒ Object
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.
26 27 28 |
# File 'lib/core/variable/StatementVariable.rb', line 26 def copy_contextual_variable return copy end |
#destructive_instance_calls(available = []) ⇒ Object
50 51 52 |
# File 'lib/core/variable/StatementVariable.rb', line 50 def destructive_instance_calls(available=[]) return [] end |
#equivalent?(to) ⇒ Boolean
Compares the passed argument and returns true if it is a unknown variable which is treated as a wild card or a variable with the same value.
TODO I’m not sure I like UnkownVariables being treated as wild cards
60 61 62 63 64 65 66 |
# File 'lib/core/variable/StatementVariable.rb', line 60 def equivalent?(to) return true if to.kind_of?(Unknown) return false if to.class != self.class # TODO I don't know if this is an equivalent comparision return false unless to.value.write == @value.write return true end |
#instance_calls(available = []) ⇒ Object
Returns an array of instance calls the Statement instances can call. Some method calls require parameters. These parameters are in the available array.
37 38 39 40 |
# File 'lib/core/variable/StatementVariable.rb', line 37 def instance_calls(available=[]) declared_variable_call = InstanceCallContainer.new(self.copy,DeclaredVariable.new) return [declared_variable_call] end |
#returning_instance_calls(available = []) ⇒ Object
Returns an array of instances calls that return a value and are therefore approriate for declaration statements.
45 46 47 |
# File 'lib/core/variable/StatementVariable.rb', line 45 def returning_instance_calls(available=[]) return instance_calls(available) end |
#variable_id=(id) ⇒ Object
Only let this method be called from fellow Fixnum classes or Unknowns
14 15 16 17 18 19 20 |
# File 'lib/core/variable/StatementVariable.rb', line 14 def variable_id=(id) # TODO This would be nicer if it wasn't so hard coded ./lib/core/variable/Unknown.rb unless caller.first.split(':')[0]==__FILE__ or caller.first.split(':')[0]=='./lib/core/statement/Statement.rb' raise StandardError.new('Illegal attempt to set variable_id') end @variable_id = id end |