Class: Dentaku::AST::If

Inherits:
Function show all
Defined in:
lib/dentaku/ast/functions/if.rb

Constant Summary

Constants inherited from Function

Function::DIG

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Function

get, numeric, register, register_class, registry

Methods inherited from Node

arity, peek, precedence

Constructor Details

#initialize(predicate, left, right) ⇒ If

Returns a new instance of If.



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

def initialize(predicate, left, right)
  @predicate = predicate
  @left      = left
  @right     = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



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

def left
  @left
end

#predicateObject (readonly)

Returns the value of attribute predicate.



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

def predicate
  @predicate
end

#rightObject (readonly)

Returns the value of attribute right.



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

def right
  @right
end

Instance Method Details

#dependencies(context = {}) ⇒ Object



26
27
28
29
# File 'lib/dentaku/ast/functions/if.rb', line 26

def dependencies(context = {})
  # TODO : short-circuit?
  (predicate.dependencies(context) + left.dependencies(context) + right.dependencies(context)).uniq
end

#node_typeObject



18
19
20
# File 'lib/dentaku/ast/functions/if.rb', line 18

def node_type
  :condition
end

#typeObject



22
23
24
# File 'lib/dentaku/ast/functions/if.rb', line 22

def type
  left.type
end

#value(context = {}) ⇒ Object



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

def value(context = {})
  predicate.value(context) ? left.value(context) : right.value(context)
end