Class: ArrayAccess
- Inherits:
-
InstanceCallContainer
- Object
- Array
- CallContainer
- InstanceCallContainer
- ArrayAccess
- Includes:
- VariableIncluded
- Defined in:
- lib/core/statement/ArrayAccess.rb
Overview
TODO I am duplicating variables here with array, index, subject and method_call
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Attributes inherited from InstanceCallContainer
#method_call, #subject, #value
Attributes inherited from CallContainer
Instance Method Summary collapse
- #cauldron_method_calls ⇒ Object
- #closure ⇒ Object
- #copy ⇒ Object
- #describe ⇒ Object
-
#equivalent?(to) ⇒ Boolean
Returns true if the passed argument is the same kind of ArrayAccess - in that it is the same class, array and index.
-
#initialize(array, index) ⇒ ArrayAccess
constructor
A new instance of ArrayAccess.
- #replace_theory_variables!(mapping) ⇒ Object
- #replace_variables_alt!(map) ⇒ Object
- #response ⇒ Object
-
#select_all(results = [], &block) ⇒ Object
Returns all the elements that match the selection criteria just like the select method.
-
#to_literal_string ⇒ Object
Returns a string calling the specfied index.
- #variable ⇒ Object
- #write ⇒ Object
Methods included from VariableIncluded
Methods inherited from InstanceCallContainer
#container=, #contains?, #contains_self?, #copy_contextual_variable, #declaration_statement, #find_actual_variable, #find_variable, #literalisable?, #literalise, #replace_variable_if, #replace_variables!, #subst!, #subst_self_for, #to_declaration, #variable_id, #variables, #write_in_context, #write_with_uniq_id
Methods included from PrintVariables
Methods inherited from CallContainer
Methods included from WriteParameters
#describe_params, #write_params
Methods inherited from Array
#contains?, #to_declaration, #to_intrinsic, #to_literal, #to_var
Constructor Details
#initialize(array, index) ⇒ ArrayAccess
Returns a new instance of ArrayAccess.
9 10 11 12 13 |
# File 'lib/core/statement/ArrayAccess.rb', line 9 def initialize(array,index) @array = array @index = index super(@array,'[Array Access]',index) end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
7 8 9 |
# File 'lib/core/statement/ArrayAccess.rb', line 7 def array @array end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
7 8 9 |
# File 'lib/core/statement/ArrayAccess.rb', line 7 def index @index end |
Instance Method Details
#cauldron_method_calls ⇒ Object
27 28 29 |
# File 'lib/core/statement/ArrayAccess.rb', line 27 def cauldron_method_calls return @array[@index].cauldron_method_calls end |
#closure ⇒ Object
39 40 41 |
# File 'lib/core/statement/ArrayAccess.rb', line 39 def closure return ['[',']'] end |
#copy ⇒ Object
31 32 33 |
# File 'lib/core/statement/ArrayAccess.rb', line 31 def copy return ArrayAccess.new(@array.copy,@index.copy) end |
#describe ⇒ Object
19 20 21 |
# File 'lib/core/statement/ArrayAccess.rb', line 19 def describe return @array.describe+'['+@index.describe+']' end |
#equivalent?(to) ⇒ Boolean
Returns true if the passed argument is the same kind of ArrayAccess - in that it is the same class, array and index.
69 70 71 72 73 74 |
# File 'lib/core/statement/ArrayAccess.rb', line 69 def equivalent?(to) return false if to.class != self.class return false unless to.array.equivalent?(@array) return false unless to.index.equivalent?(@index) return true end |
#replace_theory_variables!(mapping) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/core/statement/ArrayAccess.rb', line 82 def replace_theory_variables!(mapping) if @array.kind_of?(TheoryVariable) && mapping.has_key?(@array.theory_variable_id) @array = mapping[@array.theory_variable_id].copy elsif @array.respond_to?(:replace_theory_variables!) @array.replace_theory_variables!(mapping) end if @index.kind_of?(TheoryVariable) && mapping.has_key?(@index.theory_variable_id) @index = mapping[@index.theory_variable_id].copy elsif @index.respond_to?(:replace_theory_variables!) @index.replace_theory_variables!(mapping) end end |
#replace_variables_alt!(map) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/core/statement/ArrayAccess.rb', line 96 def replace_variables_alt!(map) if @array.kind_of?(TheoryVariable) map.each do |key,value| if @array.theory_variable_id == key.theory_variable_id @array = value break end end else @array.replace_variables_alt!(map) end # if @index.kind_of?(TheoryVariable) map.each do |key,value| if @index.theory_variable_id == key.theory_variable_id @index = value break end end elsif(@index.kind_of?(Literal)) else @index.replace_variables_alt!(map) end end |
#response ⇒ Object
23 24 25 |
# File 'lib/core/statement/ArrayAccess.rb', line 23 def response return eval(@array.literalise.write+'['+@index.write+']').to_var end |
#select_all(results = [], &block) ⇒ Object
Returns all the elements that match the selection criteria just like the select method. However is this contains an array it will seach the array.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/core/statement/ArrayAccess.rb', line 51 def select_all(results=[],&block) results.push(@array) if block.call(@array) results.push(@index) if block.call(@index) if @array.respond_to?(:select_all) @array.select_all(results,&block) end if @index.respond_to?(:select_all) @index.select_all(results,&block) end return results end |
#to_literal_string ⇒ Object
Returns a string calling the specfied index. e.g. “[4]”
78 79 80 |
# File 'lib/core/statement/ArrayAccess.rb', line 78 def to_literal_string return write end |
#variable ⇒ Object
35 36 37 |
# File 'lib/core/statement/ArrayAccess.rb', line 35 def variable return @array.copy end |
#write ⇒ Object
15 16 17 |
# File 'lib/core/statement/ArrayAccess.rb', line 15 def write return @array.write+'['+@index.write+']' end |