Sha256: 426b48e03eecf87775347c465ad8f89b3acbfcfc7980670ae63473805585c671

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Unparser
  class Emitter

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

      MAP = {
        and_asgn: '&&=',
        or_asgn:  '||='
      }.freeze

      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

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

    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

5 entries across 5 versions & 1 rubygems

Version Path
unparser-0.6.15 lib/unparser/emitter/op_assign.rb
unparser-0.6.14 lib/unparser/emitter/op_assign.rb
unparser-0.6.13 lib/unparser/emitter/op_assign.rb
unparser-0.6.12 lib/unparser/emitter/op_assign.rb
unparser-0.6.10 lib/unparser/emitter/op_assign.rb