Class: Delorean::HashArgs

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

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



787
788
789
790
791
792
793
794
795
# File 'lib/delorean/nodes.rb', line 787

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



797
798
799
800
801
802
803
804
805
806
807
808
# File 'lib/delorean/nodes.rb', line 797

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