class RuboCop::Cop::Style::ParallelAssignment::GenericCorrector

An internal class for correcting parallel assignment

Attributes

config[R]
node[R]
rescue_result[R]
rhs[R]

Public Class Methods

new(node, rhs, modifier, config, new_elements) click to toggle source
# File lib/rubocop/cop/style/parallel_assignment.rb, line 195
def initialize(node, rhs, modifier, config, new_elements)
  @node = node
  @rhs = rhs
  _, _, @rescue_result = *modifier
  @config = config
  @new_elements = new_elements
end

Public Instance Methods

correction() click to toggle source
# File lib/rubocop/cop/style/parallel_assignment.rb, line 203
def correction
  assignment.join("\n#{offset(node)}")
end
correction_range() click to toggle source
# File lib/rubocop/cop/style/parallel_assignment.rb, line 207
def correction_range
  node.source_range
end

Protected Instance Methods

assignment() click to toggle source
# File lib/rubocop/cop/style/parallel_assignment.rb, line 213
def assignment
  @new_elements.map { |lhs, rhs| "#{lhs.source} = #{source(rhs, rhs.loc)}" }
end

Private Instance Methods

cop_config() click to toggle source
# File lib/rubocop/cop/style/parallel_assignment.rb, line 234
def cop_config
  @config.for_cop('Style/ParallelAssignment')
end
extract_sources(node) click to toggle source
# File lib/rubocop/cop/style/parallel_assignment.rb, line 230
def extract_sources(node)
  node.children.map(&:source)
end
source(node, loc) click to toggle source
# File lib/rubocop/cop/style/parallel_assignment.rb, line 219
def source(node, loc)
  # __FILE__ is treated as a StrNode but has no begin
  if node.str_type? && loc.respond_to?(:begin) && loc.begin.nil?
    "'#{node.source}'"
  elsif node.sym_type? && loc.begin.nil?
    ":#{node.source}"
  else
    node.source
  end
end