Sha256: 9d5072613449c27b370a5f22f6f92b0e67cd3e4e5de6bff58bc437e894f8f9f2

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

module Unparser
  class Emitter
    class Send
      # Emitter for binary sends
      class Binary < self

      private

        # Return undefined
        #
        # @return [undefined]
        #
        # @api private
        #
        def dispatch
          emit_receiver
          emit_operator
          emit_right
        end

        # Emit receiver
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_receiver
          emit_unambiguous_receiver
          write(T_DOT) if parentheses?
        end

        # Emit operator
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_operator
          parens = parentheses? ? EMPTY_STRING : WS
          parentheses(parens, parens) { write(selector) }
        end

        # Return right node
        #
        # @return [Parser::AST::Node]
        #
        # @api private
        #
        def right_node
          children[2]
        end

        # Test for splat argument
        #
        # @return [true]
        #   if first argument is a splat
        #
        # @return [false]
        #   otherwise
        #
        # @api private
        #
        def splat?
          right_node.type == :splat
        end

        # Test if parentheses are needed
        #
        # @return [true]
        #   if parenthes are needed
        #
        # @return [false]
        #   otherwise
        #
        # @api private
        #
        def parentheses?
          splat? || children.length >= 4
        end
        memoize :parentheses?

        # Emit right
        #
        # @return [undefined]
        #
        # @api private
        #
        def emit_right
          node = right_node
          if parentheses?
            parentheses { delimited(children[2..-1]) }
            return
          end
          visit(node)
        end

      end # Binary
    end # Send
  end # Emitter
end # Unparser

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unparser-0.0.8 lib/unparser/emitter/send/binary.rb
unparser-0.0.7 lib/unparser/emitter/send/binary.rb
unparser-0.0.6 lib/unparser/emitter/send/binary.rb
unparser-0.0.5 lib/unparser/emitter/send/binary.rb
unparser-0.0.4 lib/unparser/emitter/send/binary.rb
unparser-0.0.3 lib/unparser/emitter/send/binary.rb