class Dhallish::Ast::IfThenElseNode
Attributes
cond[RW]
iffalse[RW]
iftrue[RW]
Public Class Methods
new(cond, iftrue, iffalse)
click to toggle source
# File lib/ast.rb, line 77 def initialize(cond, iftrue, iffalse) @cond = cond @iftrue = iftrue @iffalse = iffalse end
Public Instance Methods
compute_type(ctx)
click to toggle source
# File lib/ast.rb, line 83 def compute_type(ctx) cond_type, _ = @cond.compute_type(ctx) assert ("Condition in If-Then-Else-Statement not of type Bool") { cond_type == Types::Bool } then_type = @iftrue.compute_type(ctx) else_type = @iffalse.compute_type(ctx) assert ("If-Then-Else: expressions in both branches have to be of the same type") { then_type == else_type } then_type end
evaluate(ctx)
click to toggle source
# File lib/ast.rb, line 92 def evaluate(ctx) cond = @cond.evaluate ctx if cond @iftrue.evaluate ctx else @iffalse.evaluate ctx end end