class RuboCop::AST::CaseNode

A node extension for `case` nodes. This will be used in place of a plain node when the builder constructs the AST, making its methods available to all `case` nodes within RuboCop.

Public Instance Methods

each_when() { |condition| ... } click to toggle source

Calls the given block for each `when` node in the `case` statement. If no block is given, an `Enumerator` is returned.

@return [self] if a block is given @return [Enumerator] if no block is given

# File lib/rubocop/ast/node/case_node.rb, line 22
def each_when
  return when_branches.to_enum(__method__) unless block_given?

  when_branches.each do |condition|
    yield condition
  end

  self
end
else?() click to toggle source

Checks whether this case statement has an `else` branch.

@return [Boolean] whether the `case` statement has an `else` branch

# File lib/rubocop/ast/node/case_node.rb, line 50
def else?
  loc.else
end
else_branch() click to toggle source

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.

# File lib/rubocop/ast/node/case_node.rb, line 43
def else_branch
  node_parts[-1]
end
keyword() click to toggle source

Returns the keyword of the `case` statement as a string.

@return [String] the keyword of the `case` statement

# File lib/rubocop/ast/node/case_node.rb, line 13
def keyword
  'case'
end
node_parts() click to toggle source

Custom destructuring method. This can be used to normalize destructuring for different variations of the node.

@return [Array<Node>] the different parts of the `case` statement

# File lib/rubocop/ast/node/case_node.rb, line 58
def node_parts
  to_a
end
when_branches() click to toggle source

Returns an array of all the when branches in the `case` statement.

@return [Array<WhenNode>] an array of `when` nodes

# File lib/rubocop/ast/node/case_node.rb, line 35
def when_branches
  node_parts[1...-1]
end