Class: Keisan::AST::Plus
- Inherits:
-
ArithmeticOperator
- Object
- Node
- Parent
- Operator
- ArithmeticOperator
- Keisan::AST::Plus
- Defined in:
- lib/keisan/ast/plus.rb
Instance Attribute Summary
Attributes inherited from Parent
Class Method Summary collapse
Instance Method Summary collapse
- #arity ⇒ Object
- #blank_value ⇒ Object
-
#initialize(children = [], parsing_operators = []) ⇒ Plus
constructor
A new instance of Plus.
- #symbol ⇒ Object
- #value(context = nil) ⇒ Object
Methods inherited from ArithmeticOperator
Methods inherited from Operator
Constructor Details
#initialize(children = [], parsing_operators = []) ⇒ Plus
Returns a new instance of Plus.
4 5 6 7 |
# File 'lib/keisan/ast/plus.rb', line 4 def initialize(children = [], parsing_operators = []) super convert_minus_to_plus! end |
Class Method Details
.priority ⇒ Object
9 10 11 |
# File 'lib/keisan/ast/plus.rb', line 9 def self.priority 10 end |
Instance Method Details
#arity ⇒ Object
13 14 15 |
# File 'lib/keisan/ast/plus.rb', line 13 def arity 2..Float::INFINITY end |
#blank_value ⇒ Object
21 22 23 |
# File 'lib/keisan/ast/plus.rb', line 21 def blank_value 0 end |
#symbol ⇒ Object
17 18 19 |
# File 'lib/keisan/ast/plus.rb', line 17 def symbol :+ end |
#value(context = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/keisan/ast/plus.rb', line 25 def value(context = nil) children_values = children.map {|child| child.value(context)} # Special case of string concatenation if children_values.all? {|child| child.is_a?(::String)} children_values.join # Special case of array concatenation elsif children_values.all? {|child| child.is_a?(::Array)} children_values.inject([], &:+) else children_values.inject(0, &:+) end end |