Sha256: 0e5d82d959962f1f83d0be084ce6507bb2d579d486bcdc1788530390fd03c819

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

module ToSource
  class Emitter
    # Emitter for when nodes
    class When < self

      handle(Rubinius::AST::When)

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        emit('when ')
        emit_single
        emit_conditions
        emit_splat
        indented do
          visit(node.body)
        end
      end

      # Emit single
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_single
        single = node.single
        visit(single) if single
      end

      # Emit splat
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_splat
        splat = node.splat
        return unless splat
        visit(splat)
      end

      # Emit conditions
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_conditions
        conditions = node.conditions 
        return unless conditions
        run(Util::DelimitedBody, conditions.body)
      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/when.rb
to_source-0.2.19 lib/to_source/emitter/when.rb
to_source-0.2.18 lib/to_source/emitter/when.rb
to_source-0.2.17 lib/to_source/emitter/when.rb
to_source-0.2.16 lib/to_source/emitter/when.rb