File: args.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 (45 lines) | stat: -rw-r--r-- 882 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

module Unparser
  class Emitter
    # Arguments emitter
    class Args < self
      def emit_block_arguments
        delimited(normal_arguments)

        write(',') if normal_arguments.one? && n_arg?(normal_arguments.first)

        emit_shadowargs
      end

      def emit_def_arguments
        delimited(normal_arguments)
      end

      def emit_lambda_arguments
        delimited(normal_arguments)
        emit_shadowargs
      end

    private

      def emit_shadowargs
        return if shadowargs.empty?

        write('; ')
        delimited(shadowargs)
      end

      def normal_arguments
        children.reject(&method(:n_shadowarg?))
      end
      memoize :normal_arguments

      def shadowargs
        children.select(&method(:n_shadowarg?))
      end
      memoize :shadowargs

    end # Arguments
  end # Emitter
end # Unparser