Sha256: bf8e7e02cc5953fd635e911805fb16d74ab6b0c08a32a9e760104f08d6fd1126

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8

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)

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        visit(target)
        write(WS, MAP.fetch(node.type), WS)
        visit_terminated(expression)
      end

    end # BinaryAssign

    # Emitter for op assign
    class OpAssign < self

      handle :op_asgn

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        visit(first_child)
        emit_operator
        visit(children[2])
      end

      # Emit operator
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_operator
        write(WS, children[1].to_s, T_ASN, WS)
      end

    end # OpAssign
  end # Emitte
end # Unparser

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
unparser-0.1.15 lib/unparser/emitter/op_assign.rb
unparser-0.1.14 lib/unparser/emitter/op_assign.rb
unparser-0.1.13 lib/unparser/emitter/op_assign.rb
unparser-0.1.12 lib/unparser/emitter/op_assign.rb
unparser-0.1.11 lib/unparser/emitter/op_assign.rb
unparser-0.1.10 lib/unparser/emitter/op_assign.rb
unparser-0.1.9 lib/unparser/emitter/op_assign.rb
unparser-0.1.8 lib/unparser/emitter/op_assign.rb
unparser-0.1.7 lib/unparser/emitter/op_assign.rb
unparser-0.1.6 lib/unparser/emitter/op_assign.rb