File: send.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 (66 lines) | stat: -rw-r--r-- 1,369 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

module Unparser
  module NodeDetails
    class Send
      include NodeDetails

      ASSIGN_SUFFIX    = '='.freeze
      NON_ASSIGN_RANGE = (0..-2).freeze

      private_constant(*constants(false))

      children :receiver, :selector

      public :receiver, :selector

      def selector_binary_operator?
        BINARY_OPERATORS.include?(selector)
      end

      def binary_syntax_allowed?
        selector_binary_operator? \
          && n_send?(node) \
          && arguments.one? \
          && !n_splat?(arguments.first) \
          && !n_kwargs?(arguments.first)
      end

      def selector_unary_operator?
        UNARY_OPERATORS.include?(selector)
      end

      def assignment_operator?
        assignment? && !selector_binary_operator? && !selector_unary_operator?
      end

      def arguments?
        arguments.any?
      end

      def non_assignment_selector
        if assignment?
          string_selector[NON_ASSIGN_RANGE]
        else
          string_selector
        end
      end

      def assignment?
        string_selector[-1].eql?(ASSIGN_SUFFIX)
      end
      memoize :assignment?

      def arguments
        children[2..]
      end
      memoize :arguments

      def string_selector
        selector.to_s
      end
      memoize :string_selector

    end # Send
  end # NodeDetails
end # Unparser