/
masgn_node.rb
40 lines (36 loc) · 1.02 KB
/
masgn_node.rb
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
# frozen_string_literal: true
module RuboCop
module AST
# A node extension for `masgn` nodes.
# This will be used in place of a plain node when the builder constructs
# the AST, making its methods available to all assignment nodes within RuboCop.
class MasgnNode < Node
# @return [MlhsNode] the `mlhs` node
def lhs
# The first child is a `mlhs` node
node_parts[0]
end
# @return [Array<Node>] the assignment nodes of the multiple assignment
def assignments
lhs.assignments
end
# @return [Array<Symbol>] names of all the variables being assigned
def names
assignments.map do |assignment|
if assignment.send_type?
assignment.source
else
assignment.name
end
end
end
# The expression being assigned to the variable.
#
# @return [Node] the expression being assigned.
def expression
node_parts[1]
end
alias rhs expression
end
end
end