Class: Keisan::AST::Indexing
- Inherits:
-
UnaryOperator
- Object
- Node
- Parent
- Operator
- UnaryOperator
- Keisan::AST::Indexing
- Defined in:
- lib/keisan/ast/indexing.rb
Constant Summary
Constants inherited from Operator
Operator::ARITIES, Operator::ARITY_PRIORITY_ASSOCIATIVITY, Operator::ASSOCIATIVITIES, Operator::ASSOCIATIVITY_OF_PRIORITY, Operator::PRIORITIES
Instance Attribute Summary collapse
-
#indexes ⇒ Object
readonly
Returns the value of attribute indexes.
Attributes inherited from Parent
Instance Method Summary collapse
- #evaluate(context = nil) ⇒ Object
- #evaluate_assignments(context = nil) ⇒ Object
-
#initialize(child, indexes = []) ⇒ Indexing
constructor
A new instance of Indexing.
- #replace(variable, replacement) ⇒ Object
- #simplify(context = nil) ⇒ Object
- #to_s ⇒ Object
- #value(context = nil) ⇒ Object
Methods inherited from UnaryOperator
arity, associativity, #child, priority
Methods inherited from Operator
arity, #arity, associativity, #associativity, associativity_of_priority, #blank_value, #priority, priority, #symbol, symbol
Methods inherited from Parent
#==, #deep_dup, #freeze, #unbound_functions, #unbound_variables
Methods inherited from Node
#!, #%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<=, #>, #>=, #^, #and, #coerce, #deep_dup, #differentiate, #equal, #evaluated, #false?, #not_equal, #or, #simplified, #to_cell, #to_node, #true?, #unbound_functions, #unbound_variables, #well_defined?, #|, #~
Constructor Details
#initialize(child, indexes = []) ⇒ Indexing
Returns a new instance of Indexing.
6 7 8 9 |
# File 'lib/keisan/ast/indexing.rb', line 6 def initialize(child, indexes = []) @children = [child] @indexes = indexes end |
Instance Attribute Details
#indexes ⇒ Object (readonly)
Returns the value of attribute indexes.
4 5 6 |
# File 'lib/keisan/ast/indexing.rb', line 4 def indexes @indexes end |
Instance Method Details
#evaluate(context = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/keisan/ast/indexing.rb', line 23 def evaluate(context = nil) context ||= Context.new @children = children.map {|child| child.evaluate(context)} @indexes = indexes.map {|index| index.evaluate(context)} evaluate_list(context) || evaluate_hash(context) || self end |
#evaluate_assignments(context = nil) ⇒ Object
19 20 21 |
# File 'lib/keisan/ast/indexing.rb', line 19 def evaluate_assignments(context = nil) self end |
#replace(variable, replacement) ⇒ Object
35 36 37 38 |
# File 'lib/keisan/ast/indexing.rb', line 35 def replace(variable, replacement) super @indexes = indexes.map {|index| index.replace(variable, replacement)} end |
#simplify(context = nil) ⇒ Object
31 32 33 |
# File 'lib/keisan/ast/indexing.rb', line 31 def simplify(context = nil) evaluate(context) end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/keisan/ast/indexing.rb', line 15 def to_s "(#{child.to_s})[#{indexes.map(&:to_s).join(',')}]" end |
#value(context = nil) ⇒ Object
11 12 13 |
# File 'lib/keisan/ast/indexing.rb', line 11 def value(context = nil) return child.value(context).send(:[], *indexes.map {|index| index.value(context)}) end |