Class: Delorean::IfElsifElse

Inherits:
SNode
  • Object
show all
Defined in:
lib/delorean/nodes.rb

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



674
675
676
677
678
679
680
681
682
683
684
# File 'lib/delorean/nodes.rb', line 674

def check(context, *)
  vc = v.check(context)
  e1c = e1.check(context)
  e2c = e2.check(context)

  elsifs_check = elsifs.elements.map do |node|
    [node.v.check(context), node.e1.check(context)]
  end.flatten

  vc + e1c + e2c + elsifs_check
end

#rewrite(context) ⇒ Object



686
687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/delorean/nodes.rb', line 686

def rewrite(context)
  elsifs_string = elsifs.elements.map do |node|
    "elsif (#{node.v.rewrite(context)})
       (#{node.e1.rewrite(context)})"
  end.join("\n")

  "(if (#{v.rewrite(context)})
     (#{e1.rewrite(context)})
   #{elsifs_string}
   else
     (#{e2.rewrite(context)})
  end)"
end