Class: Dentaku::AST::Arithmetic

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

Instance Attribute Summary

Attributes inherited from Operation

#left, #right

Instance Method Summary collapse

Methods inherited from Operation

#dependencies, right_associative?

Methods inherited from Node

arity, #dependencies, precedence

Constructor Details

#initializeArithmetic



8
9
10
11
12
13
# File 'lib/dentaku/ast/arithmetic.rb', line 8

def initialize(*)
  super
  unless valid_left? && valid_right?
    fail ParseError, "#{ self.class } requires numeric operands"
  end
end

Instance Method Details

#operatorObject



19
20
21
# File 'lib/dentaku/ast/arithmetic.rb', line 19

def operator
  raise "Not implemented"
end

#typeObject



15
16
17
# File 'lib/dentaku/ast/arithmetic.rb', line 15

def type
  :numeric
end

#value(context = {}) ⇒ Object



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

def value(context={})
  l = cast(left.value(context))
  r = cast(right.value(context))
  l.public_send(operator, r)
end