Sha256: 641fdf62ed842f7c09cc48d9b46e9e4b23f749177479f02e0ea17ecab6266b99

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    # A node extension for `mlhs` 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 MlhsNode < Node
      # Returns all the assignment nodes on the left hand side (LHS) of a multiple assignment.
      # These are generally assignment nodes (`lvasgn`, `ivasgn`, `cvasgn`, `gvasgn`, `casgn`)
      # but can also be `send` nodes in case of `foo.bar, ... =` or `foo[:bar], ... =`,
      # or a `splat` node for `*, ... =`.
      #
      # @return [Array<Node>] the assignment nodes of the multiple assignment LHS
      def assignments
        child_nodes.flat_map do |node|
          if node.splat_type?
            # Anonymous splats have no children
            node.child_nodes.first || node
          elsif node.mlhs_type?
            node.assignments
          else
            node
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-ast-1.36.2 lib/rubocop/ast/node/mlhs_node.rb