Class: Dentaku::AST::Negation

Inherits:
Operation 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

Constructor Details

#initialize(node) ⇒ Negation

Returns a new instance of Negation.



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

def initialize(node)
  @node = node
  fail ParseError, "Negation requires numeric operand" unless valid_node?(node)
end

Class Method Details

.arityObject



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

def self.arity
  1
end

.precedenceObject



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

def self.precedence
  40
end

.right_associative?Boolean

Returns:

  • (Boolean)


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

def self.right_associative?
  true
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



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

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

#typeObject



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

def type
  :numeric
end

#value(context = {}) ⇒ Object



9
10
11
# File 'lib/dentaku/ast/negation.rb', line 9

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