Sha256: d836abbbd5c8459357a2beb66cee963472b8b549d73e35fc1d6ffb3dec4704dc

Contents?: true

Size: 973 Bytes

Versions: 8

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

module Unparser
  class Emitter

    # Base class for and and or op-assign
    class BinaryAssign < self
      children :target, :expression

      MAP = IceNine.deep_freeze(
        and_asgn: '&&=',
        or_asgn:  '||='
      )

      handle(*MAP.keys)

      def emit_heredoc_reminders
        emitter(target).emit_heredoc_reminders
        emitter(expression).emit_heredoc_reminders
      end

    private

      def dispatch
        emitter(target).emit_mlhs
        write(' ', MAP.fetch(node.type), ' ')
        visit(expression)
      end

    end # BinaryAssign

    # Emitter for op assign
    class OpAssign < self
      handle :op_asgn

      children :target, :operator, :value

    private

      def dispatch
        emitter(first_child).emit_mlhs
        emit_operator
        visit(value)
      end

      def emit_operator
        write(' ', operator.to_s, '= ')
      end

    end # OpAssign
  end # Emitte
end # Unparser

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
unparser-0.5.7 lib/unparser/emitter/op_assign.rb
unparser-0.5.6 lib/unparser/emitter/op_assign.rb
unparser-0.5.5 lib/unparser/emitter/op_assign.rb
unparser-0.5.4 lib/unparser/emitter/op_assign.rb
unparser-0.5.3 lib/unparser/emitter/op_assign.rb
unparser-0.5.2 lib/unparser/emitter/op_assign.rb
unparser-0.5.1 lib/unparser/emitter/op_assign.rb
unparser-0.5.0 lib/unparser/emitter/op_assign.rb