Sha256: c996463aa22a64c790b4833d819659140fab449167aafc4b061e986fb26c7be8

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module ToSource
  class Emitter
    # Emitter for begin constructs
    class Begin < self

      handle(Rubinius::AST::Begin)

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        emit('begin')
        emit_body
        emit_end
      end

      # Emit body
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_body
        indent
        body = node.rescue
        case body
        when Rubinius::AST::Rescue
          emit_rescue(body)
        when Rubinius::AST::Ensure
          emit_ensure(body)
        else
          visit(body)
          unindent
        end
      end

      # Emit ensure
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_ensure(node)
        visit(node.body)
        unindent
        emit(:ensure)
        indented do
          visit(node.ensure)
        end
      end

      # Emit rescue
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_rescue(node)
        visit(node.body)
        unindent
        visit(node.rescue)
      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/begin.rb
to_source-0.2.19 lib/to_source/emitter/begin.rb
to_source-0.2.18 lib/to_source/emitter/begin.rb
to_source-0.2.17 lib/to_source/emitter/begin.rb
to_source-0.2.16 lib/to_source/emitter/begin.rb