Class: Delorean::HashArgs

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

Instance Method Summary collapse

Instance Method Details

#check(context) ⇒ Object



902
903
904
905
906
907
908
909
910
# File 'lib/delorean/nodes.rb', line 902

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



937
938
939
# File 'lib/delorean/nodes.rb', line 937

def condition?
  defined?(ifexp.e3)
end

#conditions?Boolean



941
942
943
944
945
946
947
# File 'lib/delorean/nodes.rb', line 941

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



912
913
914
915
916
917
918
919
920
921
922
923
# File 'lib/delorean/nodes.rb', line 912

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



925
926
927
928
929
930
931
# File 'lib/delorean/nodes.rb', line 925

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



933
934
935
# File 'lib/delorean/nodes.rb', line 933

def splat?
  defined?(splat)
end

#splats?Boolean



949
950
951
952
953
954
955
# File 'lib/delorean/nodes.rb', line 949

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