class RuboCop::AST::WhenNode

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

Public Instance Methods

body() click to toggle source

Returns the body of the `when` node.

@return [Node, nil] the body of the `when` node

# File lib/rubocop/ast/node/when_node.rb, line 42
def body
  node_parts[-1]
end
branch_index() click to toggle source

Returns the index of the `when` branch within the `case` statement.

@return [Integer] the index of the `when` branch

# File lib/rubocop/ast/node/when_node.rb, line 28
def branch_index
  parent.when_branches.index(self)
end
conditions() click to toggle source

Returns an array of all the conditions in the `when` branch.

@return [Array<Node>] an array of condition nodes

# File lib/rubocop/ast/node/when_node.rb, line 12
def conditions
  node_parts[0...-1]
end
each_condition(&block) click to toggle source

@deprecated Use `conditions.each`

# File lib/rubocop/ast/node/when_node.rb, line 17
def each_condition(&block)
  return conditions.to_enum(__method__) unless block

  conditions.each(&block)

  self
end
then?() click to toggle source

Checks whether the `when` node has a `then` keyword.

@return [Boolean] whether the `when` node has a `then` keyword

# File lib/rubocop/ast/node/when_node.rb, line 35
def then?
  loc.begin&.is?('then')
end