Sha256: aa7e14313cf7e56b2014e6a4ff0c982ec64f22a9bd955f4cb121022a9efebccb

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

module ToSource
  class Emitter

    # Base class for keyword with value emitters
    class KeywordValue < self

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        emit(self.class::SYMBOL)
        if value?
          emit('(')
          visit(node.value)
          emit(')')
        end
      end

      # Emitter for return nodes 
      class Return < self

        handle(Rubinius::AST::Return)
        SYMBOL = :return

      private
  
        # Perform dispatch
        #
        # @return [undefined]
        #
        # @api private
        #
        def value?
          !!node.value
        end
      end

      # Emitter for break nodes
      class Break < self

        handle(Rubinius::AST::Break)
        SYMBOL = :break

        # Test if value is present
        #
        # @return [true]
        #   if value is present
        #
        # @return [false]
        #   otherwise
        #
        # @api private
        #
        def value?
          !node.value.kind_of?(Rubinius::AST::NilLiteral)
        end

      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/keyword_value.rb
to_source-0.2.19 lib/to_source/emitter/keyword_value.rb
to_source-0.2.18 lib/to_source/emitter/keyword_value.rb
to_source-0.2.17 lib/to_source/emitter/keyword_value.rb
to_source-0.2.16 lib/to_source/emitter/keyword_value.rb