Sha256: fdbfb2bdb5e6a6d94eca30a079b33042cd5de61fd02151e3110c9e061029d86e

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

module ToSource
  class Emitter
    class SendWithArguments < Send

      handle(Rubinius::AST::SendWithArguments)

      BINARY_OPERATORS = %w(
        + - * / & | && || << >> == 
        === != <= < <=> > >= =~ !~ ^ 
        **
      ).map(&:to_sym).to_set

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        if element_reference?
          run(ElementReference)
          return
        end
        if binary_operator_method?
          run(BinaryOperatorMethod)
          return
        end
        normal_dispatch
      end
      
      # Test for element reference
      #
      # @return [true]
      #   if node is an element reference
      #
      # @return [false]
      #   otherwise
      #
      # @api private
      #
      def element_reference?
        name == :[]
      end

      # Test for binary operator method
      #
      # @return [true]
      #   if node is a binary operator method
      #
      # @return [false]
      #   otherwise
      #
      # @api private
      #
      def binary_operator_method?
        BINARY_OPERATORS.include?(name)
      end

      # Perform normal dispatch
      #
      # @return [undefined]
      #
      # @api private
      # 
      def normal_dispatch
        emit_receiver
        emit_name
        emit_arguments
        emit_block
      end

      # Emit arguments
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_arguments
        emit('(')
        emitter = visit(node.arguments)
        emit_block_pass(emitter)
        emit(')')
      end

      # Emit block pass
      #
      # @param [Class:Emitter] emitter
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_block_pass(emitter)
        return unless block_pass?
        emit(', ') if emitter.any?
        visit(block)
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
to_source-0.2.20 lib/to_source/emitter/send_with_arguments.rb
to_source-0.2.19 lib/to_source/emitter/send_with_arguments.rb
to_source-0.2.18 lib/to_source/emitter/send_with_arguments.rb
to_source-0.2.17 lib/to_source/emitter/send_with_arguments.rb
to_source-0.2.16 lib/to_source/emitter/send_with_arguments.rb