module RuboCop::Cop::VariableForce::Branch

Namespace for branch classes for each control structure.

Constants

Base

Abstract base class for branch classes. A branch represents a conditional branch in a scope.

@example

def some_scope
  do_something     # no branch

  if foo
    do_something   # branch A
    do_something   # branch A
  else
    do_something   # branch B
    if bar
      do_something # branch C (whose parent is branch B)
    end
  end

  do_something     # no branch
end

Public Class Methods

of(target_node, scope: nil) click to toggle source
# File lib/rubocop/cop/variable_force/branch.rb, line 8
def self.of(target_node, scope: nil)
  ([target_node] + target_node.ancestors).each do |node|
    return nil unless node.parent
    return nil unless scope.include?(node)
    klass = CLASSES_BY_TYPE[node.parent.type]
    next unless klass
    branch = klass.new(node, scope)
    return branch if branch.branched?
  end

  nil
end