Class: Dentaku::AST::Negation

Inherits:
Arithmetic show all
Defined in:
lib/dentaku/ast/negation.rb

Constant Summary

Constants inherited from Arithmetic

Arithmetic::DECIMAL, Arithmetic::INTEGER

Instance Attribute Summary collapse

Attributes inherited from Operation

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operation

#display_operator, max_param_count, min_param_count

Methods inherited from Node

#name, resolve_class

Constructor Details

#initialize(node) ⇒ Negation

Returns a new instance of Negation.



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

def initialize(node)
  @node = node

  unless valid_node?(node)
    raise NodeError.new(:numeric, node.type, :node),
          "#{self.class} requires numeric operands"
  end
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/dentaku/ast/negation.rb', line 4

def node
  @node
end

Class Method Details

.arityObject



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

def self.arity
  1
end

.precedenceObject



35
36
37
# File 'lib/dentaku/ast/negation.rb', line 35

def self.precedence
  40
end

.right_associative?Boolean

Returns:

  • (Boolean)


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

def self.right_associative?
  true
end

Instance Method Details

#accept(visitor) ⇒ Object



43
44
45
# File 'lib/dentaku/ast/negation.rb', line 43

def accept(visitor)
  visitor.visit_negation(self)
end

#dependencies(context = {}) ⇒ Object



39
40
41
# File 'lib/dentaku/ast/negation.rb', line 39

def dependencies(context = {})
  @node.dependencies(context)
end

#operatorObject



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

def operator
  :*
end

#typeObject



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

def type
  :numeric
end

#value(context = {}) ⇒ Object



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

def value(context = {})
  cast(@node.value(context)) * -1
end