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
Returns an array of all the when branches in the ‘case` statement.
@return [Array<Node, nil>] an array of the bodies of the when branches and the else (if any). Note that these bodies could be nil.
# File lib/rubocop/ast/node/case_node.rb, line 38 def branches bodies = when_branches.map(&:body) bodies.push(else_branch) if else? bodies end
@deprecated Use ‘when_branches.each`
# File lib/rubocop/ast/node/case_node.rb, line 19 def each_when(&block) return when_branches.to_enum(__method__) unless block when_branches.each(&block) self end
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 55 def else? loc.else 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.
# File lib/rubocop/ast/node/case_node.rb, line 48 def else_branch node_parts[-1] end
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 14 def keyword 'case' end
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 30 def when_branches node_parts[1...-1] end