Sha256: 55b348a46e2815b9b52385128d74a6464b2a41b1557300baf992fe88b41f6b5b

Contents?: true

Size: 1.01 KB

Versions: 24

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Unparser
  class Emitter
    # Emitter for case nodes
    class Case < self
      handle :case

      children :condition
      define_group :whens, 1..-2

    private

      def dispatch
        write('case')
        emit_condition
        emit_whens
        emit_else
        k_end
      end

      def emit_else
        else_branch = children.last
        return unless else_branch

        write('else')
        emit_body(else_branch)
      end

      def emit_whens
        nl
        whens.each(&method(:visit))
      end

      def emit_condition
        return unless condition

        ws
        visit(condition)
      end
    end # Case

    # Emitter for when nodes
    class When < self
      handle :when

      define_group :captures, 0..-2

    private

      def dispatch
        write('when ')
        emit_captures
        emit_optional_body(children.last)
      end

      def emit_captures
        delimited(captures)
      end

    end # When
  end # Emitter
end # Unparser

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
unparser-0.6.15 lib/unparser/emitter/case.rb
unparser-0.6.14 lib/unparser/emitter/case.rb
unparser-0.6.13 lib/unparser/emitter/case.rb
unparser-0.6.12 lib/unparser/emitter/case.rb
unparser-0.6.10 lib/unparser/emitter/case.rb
unparser-0.6.9 lib/unparser/emitter/case.rb
unparser-0.6.8 lib/unparser/emitter/case.rb
devcycle-ruby-server-sdk-2.0.0 vendor/bundle/ruby/3.0.0/gems/unparser-0.6.7/lib/unparser/emitter/case.rb
unparser-0.6.7 lib/unparser/emitter/case.rb
unparser-0.6.6 lib/unparser/emitter/case.rb
unparser-0.6.5 lib/unparser/emitter/case.rb
unparser-0.6.4 lib/unparser/emitter/case.rb
unparser-0.6.3 lib/unparser/emitter/case.rb
unparser-0.6.2 lib/unparser/emitter/case.rb
unparser-0.6.1 lib/unparser/emitter/case.rb
unparser-0.6.0 lib/unparser/emitter/case.rb
unparser-0.5.7 lib/unparser/emitter/case.rb
unparser-0.5.6 lib/unparser/emitter/case.rb
unparser-0.5.5 lib/unparser/emitter/case.rb
unparser-0.5.4 lib/unparser/emitter/case.rb