Class: RuboCop::Cop::Style::ParallelAssignment::AssignmentSorter

Inherits:
Object
  • Object
show all
Extended by:
NodePattern::Macros
Includes:
TSort
Defined in:
lib/rubocop/cop/style/parallel_assignment.rb

Overview

Helper class necessitated by silly design of TSort prior to Ruby 2.1 Newer versions have a better API, but that doesn't help us

Instance Method Summary collapse

Methods included from NodePattern::Macros

def_node_matcher, def_node_search

Constructor Details

#initialize(assignments) ⇒ AssignmentSorter

Returns a new instance of AssignmentSorter.



103
104
105
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 103

def initialize(assignments)
  @assignments = assignments
end

Instance Method Details

#tsort_each_child(assignment) ⇒ Object



111
112
113
114
115
116
117
118
119
120
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 111

def tsort_each_child(assignment)
  # yield all the assignments which must come after `assignment`
  # (due to dependencies on the previous value of the assigned var)
  my_lhs, _my_rhs = *assignment

  @assignments.each do |other|
    _other_lhs, other_rhs = *other
    yield other if uses_var?(other_rhs, var_name(my_lhs))
  end
end

#tsort_each_nodeObject



107
108
109
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 107

def tsort_each_node
  @assignments.each { |a| yield a }
end