File: match_pattern.rb

package info (click to toggle)
ruby-unparser 0.6.13-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 936 kB
  • sloc: ruby: 7,691; sh: 6; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

module Unparser
  class Emitter
    # Emitter for in pattern nodes
    class MatchPattern < self

      handle :match_pattern

      children :target, :pattern

      # Modern ast format emits `match_pattern`
      # node on single line pre 3.0, but 3.0+ uses `match_pattern_p`
      SYMBOL =
        if RUBY_VERSION < '3.0'
          ' in '
        else
          ' => '
        end

    private

      def dispatch
        visit(target)
        write(SYMBOL)
        visit(pattern)
      end
    end # MatchPattern
  end # Emitter
end # Unparser