Class: ArrayVariable
- Inherits:
-
TypeVariable
- Object
- Array
- BaseVariable
- TypeVariable
- ArrayVariable
- Defined in:
- lib/core/variable/ArrayVariable.rb
Instance Attribute Summary collapse
-
#variable_id ⇒ Object
Returns the value of attribute variable_id.
Attributes inherited from TypeVariable
Attributes inherited from BaseVariable
#instance_variable, #uniq_id_history, #value
Attributes included from Variable
Instance Method Summary collapse
-
#copy ⇒ Object
TODO Write tests for all variables to maintain uniq_id_history.
-
#initialize(*parameters) ⇒ ArrayVariable
constructor
TODO Presumes that all parameters extends TypeVariable some are literals.
-
#instance_calls(available = []) ⇒ Object
Returns an array of instance calls for the particular type variable.
-
#select_all(results = [], &block) ⇒ Object
TODO Temporary overwrite - I’m not sure how to apply select_all for array variables.
- #to_declaration ⇒ Object
- #to_literal_string ⇒ Object
Methods inherited from TypeVariable
#cauldron_method_calls, #describe, #equivalent?, #literalisable?, #literalise, #realised?
Methods inherited from BaseVariable
#destructive_instance_calls, #find_actual_variable, #realised?, reset_global_id, #returning_instance_calls, #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?, #to_intrinsic, #to_literal, #to_var, #write
Constructor Details
#initialize(*parameters) ⇒ ArrayVariable
TODO Presumes that all parameters extends TypeVariable some are literals
6 7 8 9 |
# File 'lib/core/variable/ArrayVariable.rb', line 6 def initialize(*parameters) super(parameters) parameters.each { |x| self.push(x) } end |
Instance Attribute Details
#variable_id ⇒ Object
Returns the value of attribute variable_id.
3 4 5 |
# File 'lib/core/variable/ArrayVariable.rb', line 3 def variable_id @variable_id end |
Instance Method Details
#copy ⇒ Object
TODO Write tests for all variables to maintain uniq_id_history
19 20 21 22 23 24 25 26 |
# File 'lib/core/variable/ArrayVariable.rb', line 19 def copy result = ArrayVariable.new(*self.collect {|x| x.copy} ) {{:variable_id => self.variable_id,:uniq_id=>@uniq_id,:uniq_id_history=>@uniq_id_history.copy}} #result.variable_id = variable_id result.instance_variable = @instance_variable # TODO I need to check uniq_id for 'copy' accross all the variables #result.uniq_id = @uniq_id return result end |
#instance_calls(available = []) ⇒ Object
Returns an array of instance calls for the particular type variable. For example:
StringVariable.new(‘test’).instance_calls
might return [var.chop,var.length]
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/core/variable/ArrayVariable.rb', line 50 def instance_calls(available=[]) # Add the chop instance call results = [] results.push InstanceCallContainer.new(self.copy,ArrayLength.new) # Attempt to create access calls - firstly with index self.length.times do |i| results.push ArrayAccess.new(self.copy,Literal.new(i)) end return results end |
#select_all(results = [], &block) ⇒ Object
TODO Temporary overwrite - I’m not sure how to apply select_all for array variables.
When you write the variable it's var5 but it still contains addition variables.
13 14 15 16 |
# File 'lib/core/variable/ArrayVariable.rb', line 13 def select_all(results=[],&block) #results.push(self) if block.call(self) return results end |
#to_declaration ⇒ Object
28 29 30 |
# File 'lib/core/variable/ArrayVariable.rb', line 28 def to_declaration return VariableDeclaration.new('ArrayVariable',*@value.collect {|x| x.to_declaration}) end |
#to_literal_string ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/core/variable/ArrayVariable.rb', line 65 def to_literal_string l = '[' self.each do |x| l += x.to_literal_string unless x.object_id == self.last.object_id l += ',' end end l += ']' end |