Class: Dentaku::AST::Negation

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

Instance Attribute Summary

Attributes inherited from Operation

#left, #right

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

peek

Constructor Details

#initialize(node) ⇒ Negation

Returns a new instance of Negation.



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

def initialize(node)
  @node = node

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

Class Method Details

.arityObject



25
26
27
# File 'lib/dentaku/ast/negation.rb', line 25

def self.arity
  1
end

.precedenceObject



33
34
35
# File 'lib/dentaku/ast/negation.rb', line 33

def self.precedence
  40
end

.right_associative?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/dentaku/ast/negation.rb', line 29

def self.right_associative?
  true
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



37
38
39
# File 'lib/dentaku/ast/negation.rb', line 37

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

#operatorObject



13
14
15
# File 'lib/dentaku/ast/negation.rb', line 13

def operator
  :*
end

#typeObject



21
22
23
# File 'lib/dentaku/ast/negation.rb', line 21

def type
  :numeric
end

#value(context = {}) ⇒ Object



17
18
19
# File 'lib/dentaku/ast/negation.rb', line 17

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