Class: Delorean::HashArgs

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

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



637
638
639
640
641
642
643
644
645
# File 'lib/delorean/nodes.rb', line 637

def check(context, *)
  [
    e0.check(context),
    (e1.check(context) unless defined?(splat)),
    (ifexp.e3.check(context) if defined?(ifexp.e3)),
    (args_rest.al.check(context) if
      defined?(args_rest.al) && !args_rest.al.empty?),
  ].compact.sum
end

#rewrite(context, var) ⇒ Object



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

def rewrite(context, var)
  res = if defined?(splat)
          "#{var}.merge!(#{e0.rewrite(context)})"
        else
          "#{var}[#{e0.rewrite(context)}]=(#{e1.rewrite(context)})"
        end
  res += " if (#{ifexp.e3.rewrite(context)})" if defined?(ifexp.e3)
  res += ';'
  res += args_rest.al.rewrite(context, var) if
    defined?(args_rest.al) && !args_rest.al.text_value.empty?
  res
end