Class: Delorean::KwArgs

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

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



547
548
549
550
551
552
553
# File 'lib/delorean/nodes.rb', line 547

def check(context, *)
  [arg0.check(context),
   (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, i = 0) ⇒ Object



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/delorean/nodes.rb', line 555

def rewrite(context, var, i=0)
  arg0_rw = arg0.rewrite(context)

  if defined?(splat)
    res = "#{var}.merge!(#{arg0_rw})"
  else
    k_rw = defined?(k.i) ? "'#{k.i.text_value}'" : i.to_s
    res = "#{var}[#{k_rw}]=(#{arg0_rw})"
    i += 1 unless defined?(k.i)
  end

  res += " if (#{ifexp.e3.rewrite(context)})" if defined?(ifexp.e3)
  res += ";"
  res += args_rest.al.rewrite(context, var, i) if
    defined?(args_rest.al) && !args_rest.al.text_value.empty?
  res
end