Sha256: 898a870518e67b6cb7e15f249bc4bc3eaff6053916f18d56dafaef716ad3e378

Contents?: true

Size: 850 Bytes

Versions: 8

Compression:

Stored size: 850 Bytes

Contents

# frozen_string_literal: true

module Unparser
  class Emitter
    # Emitter for Hash literals
    class Hash < self
      handle :hash

      def emit_last_argument_hash
        if children.empty?
          write('{}')
        else
          emit_hash_body
        end
      end

      def emit_heredoc_reminders
        children.each(&method(:emit_heredoc_reminder_member))
      end

    private

      def dispatch
        if children.empty?
          write('{}')
        else
          parentheses('{', '}') do
            write(' ')
            emit_hash_body
            write(' ')
          end
        end
      end

      def emit_heredoc_reminder_member(node)
        emitter(node.children.last).emit_heredoc_reminders
      end

      def emit_hash_body
        delimited(children)
      end
    end # Hash
  end # Emitter
end # Unparser

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
unparser-0.6.5 lib/unparser/emitter/hash.rb
unparser-0.6.4 lib/unparser/emitter/hash.rb
unparser-0.6.3 lib/unparser/emitter/hash.rb
unparser-0.6.2 lib/unparser/emitter/hash.rb
unparser-0.6.1 lib/unparser/emitter/hash.rb
unparser-0.6.0 lib/unparser/emitter/hash.rb
unparser-0.5.7 lib/unparser/emitter/hash.rb
unparser-0.5.6 lib/unparser/emitter/hash.rb