Sha256: 727838044785d514691ba73592fda9db0691c37093ffd03b471baec752885737

Contents?: true

Size: 1.29 KB

Versions: 24

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Unparser
  class Emitter

    # Base class for assignment emitters
    class Assignment < self
      BINARY_OPERATOR = %i[and or].freeze

      def symbol_name
        true
      end

      def emit_heredoc_reminders
        return unless right

        emitter(right).emit_heredoc_reminders
      end

    private

      def dispatch
        emit_left
        emit_right
      end

      def emit_right
        return unless right

        write(' = ')

        if BINARY_OPERATOR.include?(right.type)
          writer_with(Writer::Binary, right).emit_operator
        else
          visit(right)
        end
      end

      abstract_method :emit_left

      # Variable assignment emitter
      class Variable < self

        handle :lvasgn, :ivasgn, :cvasgn, :gvasgn

        children :name, :right

      private

        def emit_left
          write(name.to_s)
        end

      end # Variable

      # Constant assignment emitter
      class Constant < self

        handle :casgn

        children :base, :name, :right

      private

        def emit_left
          if base
            visit(base)
            write('::') unless n_cbase?(base)
          end
          write(name.to_s)
        end

      end # Constant
    end # Assignment
  end # Emitter
end # Unparser

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
unparser-0.6.15 lib/unparser/emitter/assignment.rb
unparser-0.6.14 lib/unparser/emitter/assignment.rb
unparser-0.6.13 lib/unparser/emitter/assignment.rb
unparser-0.6.12 lib/unparser/emitter/assignment.rb
unparser-0.6.10 lib/unparser/emitter/assignment.rb
unparser-0.6.9 lib/unparser/emitter/assignment.rb
unparser-0.6.8 lib/unparser/emitter/assignment.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/unparser-0.6.7/lib/unparser/emitter/assignment.rb
unparser-0.6.7 lib/unparser/emitter/assignment.rb
unparser-0.6.6 lib/unparser/emitter/assignment.rb
unparser-0.6.5 lib/unparser/emitter/assignment.rb
unparser-0.6.4 lib/unparser/emitter/assignment.rb
unparser-0.6.3 lib/unparser/emitter/assignment.rb
unparser-0.6.2 lib/unparser/emitter/assignment.rb
unparser-0.6.1 lib/unparser/emitter/assignment.rb
unparser-0.6.0 lib/unparser/emitter/assignment.rb
unparser-0.5.7 lib/unparser/emitter/assignment.rb
unparser-0.5.6 lib/unparser/emitter/assignment.rb
unparser-0.5.5 lib/unparser/emitter/assignment.rb
unparser-0.5.4 lib/unparser/emitter/assignment.rb