Class: Dentaku::AST::If
Constant Summary
Constants inherited
from Function
Function::DIG
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Function
#accept, get, numeric, register, register_class, registry
Methods inherited from Node
arity, #name, precedence, resolve_class
Constructor Details
#initialize(predicate, left, right) ⇒ If
Returns a new instance of If.
16
17
18
19
20
|
# File 'lib/dentaku/ast/functions/if.rb', line 16
def initialize(predicate, left, right)
@predicate = predicate
@left = left
@right = right
end
|
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
6
7
8
|
# File 'lib/dentaku/ast/functions/if.rb', line 6
def left
@left
end
|
#predicate ⇒ Object
Returns the value of attribute predicate.
6
7
8
|
# File 'lib/dentaku/ast/functions/if.rb', line 6
def predicate
@predicate
end
|
#right ⇒ Object
Returns the value of attribute right.
6
7
8
|
# File 'lib/dentaku/ast/functions/if.rb', line 6
def right
@right
end
|
Class Method Details
.max_param_count ⇒ Object
12
13
14
|
# File 'lib/dentaku/ast/functions/if.rb', line 12
def self.max_param_count
3
end
|
.min_param_count ⇒ Object
8
9
10
|
# File 'lib/dentaku/ast/functions/if.rb', line 8
def self.min_param_count
3
end
|
Instance Method Details
#args ⇒ Object
22
23
24
|
# File 'lib/dentaku/ast/functions/if.rb', line 22
def args
[predicate, left, right]
end
|
#dependencies(context = {}) ⇒ Object
38
39
40
41
42
|
# File 'lib/dentaku/ast/functions/if.rb', line 38
def dependencies(context = {})
predicate.value(context) ? left.dependencies(context) : right.dependencies(context)
rescue Dentaku::Error, Dentaku::ArgumentError, Dentaku::ZeroDivisionError
args.flat_map { |arg| arg.dependencies(context) }.uniq
end
|
#node_type ⇒ Object
30
31
32
|
# File 'lib/dentaku/ast/functions/if.rb', line 30
def node_type
:condition
end
|
#type ⇒ Object
34
35
36
|
# File 'lib/dentaku/ast/functions/if.rb', line 34
def type
left.type
end
|
#value(context = {}) ⇒ Object
26
27
28
|
# File 'lib/dentaku/ast/functions/if.rb', line 26
def value(context = {})
predicate.value(context) ? left.value(context) : right.value(context)
end
|