123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Cop::Style::ParallelAssignment::GenericCorrector

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/rubocop/cop/style/parallel_assignment.rb

Overview

An internal class for correcting parallel assignment

Constant Summary

::RuboCop::Cop::Alignment - Included

SPACE

Class Method Summary

Instance Attribute Summary

::RuboCop::Cop::Alignment - Included

Instance Method Summary

Constructor Details

.new(node, rhs, modifier, config, new_elements) ⇒ GenericCorrector

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 190

def initialize(node, rhs, modifier, config, new_elements)
  @node = node
  @rhs = rhs
  _, _, @rescue_result = *modifier
  @config = config
  @new_elements = new_elements
end

Instance Attribute Details

#config (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 188

attr_reader :node, :rhs, :rescue_result, :config

#node (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 188

attr_reader :node, :rhs, :rescue_result, :config

#rescue_result (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 188

attr_reader :node, :rhs, :rescue_result, :config

#rhs (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 188

attr_reader :node, :rhs, :rescue_result, :config

Instance Method Details

#cop_config (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 229

def cop_config
  @config.for_cop('Style/ParallelAssignment')
end

#correction

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 198

def correction
  assignment.join("\n#{offset(node)}")
end

#correction_range

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 202

def correction_range
  node.source_range
end

#extract_sources(node) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 225

def extract_sources(node)
  node.children.map(&:source)
end

#source(node, loc) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/style/parallel_assignment.rb', line 214

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