Sha256: 84dc0c099f185495e67553ac72d2215360be985af23171a3f19b41de5452accd

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    # A node extension for `case_match` nodes. This will be used in place of
    # a plain node when the builder constructs the AST, making its methods
    # available to all `case_match` nodes within RuboCop.
    class CaseMatchNode < Node
      include ConditionalNode

      # Returns the keyword of the `case` statement as a string.
      #
      # @return [String] the keyword of the `case` statement
      def keyword
        'case'
      end

      # @deprecated Use `in_pattern_branches.each`
      def each_in_pattern(&block)
        return in_pattern_branches.to_enum(__method__) unless block

        in_pattern_branches.each(&block)

        self
      end

      # Returns an array of all the when branches in the `case` statement.
      #
      # @return [Array<Node>] an array of `in_pattern` nodes
      def in_pattern_branches
        node_parts[1...-1]
      end

      # Returns the else branch of the `case` statement, if any.
      #
      # @return [Node] the else branch node of the `case` statement
      # @return [nil] if the case statement does not have an else branch.
      def else_branch
        node_parts[-1]
      end

      # Checks whether this case statement has an `else` branch.
      #
      # @return [Boolean] whether the `case` statement has an `else` branch
      def else?
        !loc.else.nil?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-ast-1.5.0/lib/rubocop/ast/node/case_match_node.rb
rubocop-ast-1.5.0 lib/rubocop/ast/node/case_match_node.rb
rubocop-ast-1.4.2 lib/rubocop/ast/node/case_match_node.rb
rubocop-ast-1.4.1 lib/rubocop/ast/node/case_match_node.rb
rubocop-ast-1.4.0 lib/rubocop/ast/node/case_match_node.rb
rubocop-ast-1.3.0 lib/rubocop/ast/node/case_match_node.rb
rubocop-ast-1.2.0 lib/rubocop/ast/node/case_match_node.rb