Class: Delorean::HashArgs

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

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



871
872
873
874
875
876
877
878
879
# File 'lib/delorean/nodes.rb', line 871

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

#condition?Boolean

Returns:

  • (Boolean)


906
907
908
# File 'lib/delorean/nodes.rb', line 906

def condition?
  defined?(ifexp.e3)
end

#conditions?Boolean

Returns:

  • (Boolean)


910
911
912
913
914
915
916
# File 'lib/delorean/nodes.rb', line 910

def conditions?
  return true if condition?
  return false unless defined?(args_rest.al)
  return false if args_rest.al.text_value.empty?

  args_rest.al.conditions?
end

#rewrite(context, var) ⇒ Object



881
882
883
884
885
886
887
888
889
890
891
892
# File 'lib/delorean/nodes.rb', line 881

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

#rewrite_with_literal(context) ⇒ Object



894
895
896
897
898
899
900
# File 'lib/delorean/nodes.rb', line 894

def rewrite_with_literal(context)
  res = "#{e0.rewrite(context)} => #{e1.rewrite(context)},"
  res += args_rest.al.rewrite_with_literal(context) if
    defined?(args_rest.al) && !args_rest.al.text_value.empty?

  res
end

#splat?Boolean

Returns:

  • (Boolean)


902
903
904
# File 'lib/delorean/nodes.rb', line 902

def splat?
  defined?(splat)
end

#splats?Boolean

Returns:

  • (Boolean)


918
919
920
921
922
923
924
# File 'lib/delorean/nodes.rb', line 918

def splats?
  return true if splat?
  return false unless defined?(args_rest.al)
  return false if args_rest.al.text_value.empty?

  args_rest.al.splats?
end