Sha256: c388aa579b8da0c9b73f7550535dca844a68e1db70cf82944c4d7cafc11d099e

Contents?: true

Size: 1.11 KB

Versions: 13

Compression:

Stored size: 1.11 KB

Contents

module Unparser
  class Emitter
    # Emitter for rescue nodes
    class Rescue < self

      handle :rescue

      children :body

    private

      # Perform dispatch
      #
      # @return [undefined]
      #
      # @api private
      #
      def dispatch
        if body
          visit_indented(body)
        else
          nl
        end
        rescue_bodies.each do |child|
          visit(child)
        end
        emit_else
      end

      # Return rescue bodies
      #
      # @return [Enumerable<Parser::AST::Node>]
      #
      # @api private
      #
      def rescue_bodies
        children[1..-2]
      end

      # Emit else
      #
      # @return [undefined]
      #
      # @api private
      #
      def emit_else
        return unless else_branch
        write(K_ELSE)
        visit_indented(else_branch)
      end

      # Return else body
      #
      # @return [Parser::AST::Node]
      #   if else body is present
      #
      # @return [nil]
      #   otherwise
      #
      # @api private
      #
      def else_branch
        children.last
      end

    end # Rescue
  end # Emitter
end # Unparser

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
unparser-0.1.5 lib/unparser/emitter/rescue.rb
unparser-0.1.4 lib/unparser/emitter/rescue.rb
unparser-0.1.3 lib/unparser/emitter/rescue.rb
unparser-0.1.2 lib/unparser/emitter/rescue.rb
unparser-0.1.1 lib/unparser/emitter/rescue.rb
unparser-0.1.0 lib/unparser/emitter/rescue.rb
unparser-0.0.18 lib/unparser/emitter/rescue.rb
unparser-0.0.16 lib/unparser/emitter/rescue.rb
unparser-0.0.15 lib/unparser/emitter/rescue.rb
unparser-0.0.14 lib/unparser/emitter/rescue.rb
unparser-0.0.13 lib/unparser/emitter/rescue.rb
unparser-0.0.12 lib/unparser/emitter/rescue.rb
unparser-0.0.11 lib/unparser/emitter/rescue.rb