Class: Dentaku::AST::Arithmetic

Inherits:
Operation show all
Defined in:
lib/dentaku/ast/arithmetic.rb

Constant Summary

Constants inherited from Node

Node::STATIC_CONTEXT, Node::STATIC_MODE_KEY

Instance Attribute Summary

Attributes inherited from Operation

#left, #right

Instance Method Summary collapse

Methods inherited from Operation

#accept, #dependencies, #display_operator, max_param_count, min_param_count, #operator_spacing, right_associative?

Methods inherited from Node

arity, #dependencies, #name, precedence, #pure?, resolve_class

Constructor Details

#initializeArithmetic

Returns a new instance of Arithmetic.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dentaku/ast/arithmetic.rb', line 9

def initialize(*)
  super

  unless valid_left?
    raise NodeError.new(:incompatible, left.type, :left),
          "#{self.class} requires operands that are numeric or compatible types, not #{left.type}"
  end

  unless valid_right?
    raise NodeError.new(:incompatible, right.type, :right),
          "#{self.class} requires operands that are numeric or compatible types, not #{right.type}"
  end
end

Instance Method Details

#operatorObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/dentaku/ast/arithmetic.rb', line 27

def operator
  raise NotImplementedError
end

#typeObject



23
24
25
# File 'lib/dentaku/ast/arithmetic.rb', line 23

def type
  :numeric
end

#value(context = {}) ⇒ Object



31
32
33
# File 'lib/dentaku/ast/arithmetic.rb', line 31

def value(context = {})
  calculate(left.value(context), right.value(context))
end