Class: RuboCop::Cop::VariableForce::Branch::Base Private
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Struct
|
|
Instance Chain:
self,
Struct
|
|
Inherits: |
Struct
|
Defined in: | lib/rubocop/cop/variable_force/branch.rb |
Overview
Abstract base class for branch classes. A branch represents a conditional branch in a scope.
Class Method Summary
- .classes Internal use only
- .define_predicate(name, child_index: nil) Internal use only
- .inherited(subclass) Internal use only
- .type Internal use only
Instance Attribute Summary
- #always_run? ⇒ Boolean readonly Internal use only
- #branched? ⇒ Boolean readonly Internal use only
-
#child_node
rw
Internal use only
Abstract base class for branch classes.
- #may_jump_to_other_branch? ⇒ Boolean readonly Internal use only
- #may_run_incompletely? ⇒ Boolean readonly Internal use only
-
#scope
rw
Internal use only
Abstract base class for branch classes.
Instance Method Summary
- #==(other) (also: #eql?) Internal use only
- #control_node Internal use only
- #each_ancestor(include_self: false) {|_self| ... } Internal use only
-
#eql?(other)
Alias for #==.
- #exclusive_with?(other) ⇒ Boolean Internal use only
- #hash Internal use only
- #parent Internal use only
- #scan_ancestors private Internal use only
Class Method Details
.classes
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 43
def self.classes @classes ||= [] end
.define_predicate(name, child_index: nil)
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 56
def self.define_predicate(name, child_index: nil) define_method(name) do target_node = control_node.children[child_index] # We don't use Kernel#Array here # because it invokes Node#to_a rather than wrapping with an array. if target_node.is_a?(Array) target_node.any? { |node| node.equal?(child_node) } else target_node.equal?(child_node) end end end
.inherited(subclass)
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 47
def self.inherited(subclass) super classes << subclass end
.type
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 52
def self.type name.split('::').last.gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym end
Instance Attribute Details
#always_run? ⇒ Boolean
(readonly)
# File 'lib/rubocop/cop/variable_force/branch.rb', line 92
def always_run? raise NotImplementedError end
#branched? ⇒ Boolean
(readonly)
# File 'lib/rubocop/cop/variable_force/branch.rb', line 88
def branched? !always_run? end
#child_node (rw)
Abstract base class for branch classes. A branch represents a conditional branch in a scope.
# File 'lib/rubocop/cop/variable_force/branch.rb', line 42
Base = Struct.new(:child_node, :scope)
#may_jump_to_other_branch? ⇒ Boolean
(readonly)
# File 'lib/rubocop/cop/variable_force/branch.rb', line 96
def may_jump_to_other_branch? false end
#may_run_incompletely? ⇒ Boolean
(readonly)
# File 'lib/rubocop/cop/variable_force/branch.rb', line 100
def may_run_incompletely? false end
#scope (rw)
Abstract base class for branch classes. A branch represents a conditional branch in a scope.
# File 'lib/rubocop/cop/variable_force/branch.rb', line 42
Base = Struct.new(:child_node, :scope)
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 121
def ==(other) return false unless other control_node.equal?(other.control_node) && child_node.equal?(other.child_node) end
#control_node
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 70
def control_node child_node.parent end
#each_ancestor(include_self: false) {|_self| ... }
# File 'lib/rubocop/cop/variable_force/branch.rb', line 80
def each_ancestor(include_self: false, &block) return to_enum(__method__, include_self: include_self) unless block yield self if include_self scan_ancestors(&block) self end
#eql?(other)
Alias for #==.
# File 'lib/rubocop/cop/variable_force/branch.rb', line 127
alias_method :eql?, :==
#exclusive_with?(other) ⇒ Boolean
# File 'lib/rubocop/cop/variable_force/branch.rb', line 104
def exclusive_with?(other) return false unless other return false if may_jump_to_other_branch? other.each_ancestor(include_self: true) do |other_ancestor| if control_node.equal?(other_ancestor.control_node) return !child_node.equal?(other_ancestor.child_node) end end if parent parent.exclusive_with?(other) else false end end
#hash
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 129
def hash [control_node.object_id, control_node.object_id].hash end
#parent
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 74
def parent return @parent if instance_variable_defined?(:@parent) @parent = Branch.of(control_node, scope: scope) end
#scan_ancestors (private)
[ GitHub ]# File 'lib/rubocop/cop/variable_force/branch.rb', line 135
def scan_ancestors branch = self while (branch = branch.parent) yield branch end end