Class: Delorean::IfElsifElse

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

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



632
633
634
635
636
637
638
639
640
641
642
# File 'lib/delorean/nodes.rb', line 632

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



644
645
646
647
648
649
650
651
652
653
654
655
656
# File 'lib/delorean/nodes.rb', line 644

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