Class: C::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/castaddon/index.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#dimension(count = 1) ⇒ Object

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.



28
29
30
# File 'lib/castaddon/index.rb', line 28

def dimension(count=1)
	return (self.expr.index?) ? self.expr.dimension(count+1) : count
end

#index_at_dimension(dimension) ⇒ Object

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.



35
36
37
# File 'lib/castaddon/index.rb', line 35

def index_at_dimension(dimension)
	return (dimension == 0) ? self.index : self.expr.index_at_dimension(dimension-1)
end

#variable_nameObject

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.



13
14
15
# File 'lib/castaddon/index.rb', line 13

def variable_name
	return (self.expr.variable?) ? self.expr.name : self.expr.variable_name
end

#variable_name=(name) ⇒ Object

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.



21
22
23
# File 'lib/castaddon/index.rb', line 21

def variable_name=(name)
	(self.expr.variable?) ? self.expr.name = name : self.expr.variable_name=(name)
end