Class: Dentaku::AST::Comparator

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

Instance Attribute Summary

Attributes inherited from Operation

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operation

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

Methods inherited from Node

arity, #dependencies, #name, peek

Constructor Details

This class inherits a constructor from Dentaku::AST::Operation

Class Method Details

.precedenceObject



6
7
8
# File 'lib/dentaku/ast/comparators.rb', line 6

def self.precedence
  5
end

Instance Method Details

#operatorObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/dentaku/ast/comparators.rb', line 14

def operator
  raise NotImplementedError
end

#typeObject



10
11
12
# File 'lib/dentaku/ast/comparators.rb', line 10

def type
  :logical
end

#value(context = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/dentaku/ast/comparators.rb', line 18

def value(context = {})
  l = validate_value(cast(left.value(context)))
  r = validate_value(cast(right.value(context)))

  l.public_send(operator, r)
rescue ::ArgumentError => e
  raise Dentaku::ArgumentError.for(:incompatible_type, value: r, for: l.class), e.message
end