Method: Delorean::HashComprehension#rewrite

Defined in:
lib/delorean/nodes.rb

#rewrite(context) ⇒ Object



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/delorean/nodes.rb', line 513

def rewrite(context)
  res = ["(#{e1.rewrite(context)})"]
  unpack_vars = args.check(context)
  unpack_vars.each {|vname| context.parse_define_var(vname)}
  args_str = args.rewrite(context)

  hid = @@comp_count += 1

  res << ".select{|#{args_str}| (#{ifexp.ei.rewrite(context)}) }" if
    defined?(ifexp.ei)

  unpack_str = unpack_vars.count > 1 ? "(#{args_str})" : args_str

  res << ".each_with_object({}){|#{unpack_str}, _h#{hid}| " +
    "_h#{hid}[#{el.rewrite(context)}]=(#{er.rewrite(context)})}"

  unpack_vars.each {|vname| context.parse_undef_var(vname)}
  res.sum
end