class RuboCop::Cop::Style::VariableInterpolation

This cop checks for variable interpolation (like “#@ivar”).

Constants

MSG

Public Instance Methods

on_dstr(node) click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 10
def on_dstr(node)
  check_for_interpolation(node)
end
on_regexp(node) click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 14
def on_regexp(node)
  check_for_interpolation(node)
end
on_xstr(node) click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 18
def on_xstr(node)
  check_for_interpolation(node)
end

Private Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 34
def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.source_range, "{#{node.source}}")
  end
end
check_for_interpolation(node) click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 24
def check_for_interpolation(node)
  var_nodes(node.children).each do |var_node|
    add_offense(var_node)
  end
end
message(node) click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 30
def message(node)
  format(MSG, node.source, node.source)
end
var_nodes(nodes) click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 40
def var_nodes(nodes)
  nodes.select { |n| n.variable? || n.reference? }
end