class C::Index
This class provides an extention to the CAST index class. The class contains a number of functions applicable to array accesses of the form ‘array[y]’ or ‘vector’.
The provided methods are helpers to extend the CAST functionality and to clean-up the Bones
classes.
Public Instance Methods
This method returns the dimension of an index expression. It starts at dimension 1, but if it can find a new dimension it will increment the count and call itself again.
# File lib/castaddon/index.rb 28 def dimension(count=1) 29 return (self.expr.index?) ? self.expr.dimension(count+1) : count 30 end
This method returns the index itself at a given dimension. It uses recursion to iterate through the dimensions, but will eventually return a new index node.
# File lib/castaddon/index.rb 35 def index_at_dimension(dimension) 36 return (dimension == 0) ? self.index : self.expr.index_at_dimension(dimension-1) 37 end
This method is a recursive method which gets the name of a variable from the index definition. Depending on the number of dimensions, it will go deeper into the structure and eventually return the name.
# File lib/castaddon/index.rb 13 def variable_name 14 return (self.expr.variable?) ? self.expr.name : self.expr.variable_name 15 end
This method is a recursive method which sets the name of a variable from the index definition. Depending on the number of dimensions, it will go deeper into the structure and eventually set the name.
# File lib/castaddon/index.rb 21 def variable_name=(name) 22 (self.expr.variable?) ? self.expr.name = name : self.expr.variable_name=(name) 23 end