Sha256: 90a8c1cd4ba49552d5113df0cea9ed495f93c576ace9f5018ae25300b50b9041

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module ToSource
  class Emitter
    # Base class for binary operator emitters
    class BinaryOperator < self

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        parantheses do
          emit_left
          emit(" #{self.class::SYMBOL} ")
          emit_right
        end
      end

      # Emit left
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_left
        parantheses do 
          visit(node.left)
        end
      end

      # Emit right
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_right
        parantheses do
          visit(node.right)
        end
      end

      # Emitter for binary or operator
      class Or < self

        handle(Rubinius::AST::Or)
        SYMBOL = :'||'

      end

      # Emitter for binary and operator
      class And < self

        handle(Rubinius::AST::And)
        SYMBOL = :'&&'

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
to_source-0.2.18 lib/to_source/emitter/binary_operator.rb
to_source-0.2.17 lib/to_source/emitter/binary_operator.rb
to_source-0.2.16 lib/to_source/emitter/binary_operator.rb