class RubbyCop::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/rubbycop/cop/style/variable_interpolation.rb, line 11 def on_dstr(node) check_for_interpolation(node) end
on_regexp(node)
click to toggle source
# File lib/rubbycop/cop/style/variable_interpolation.rb, line 15 def on_regexp(node) check_for_interpolation(node) end
on_xstr(node)
click to toggle source
# File lib/rubbycop/cop/style/variable_interpolation.rb, line 19 def on_xstr(node) check_for_interpolation(node) end
Private Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubbycop/cop/style/variable_interpolation.rb, line 32 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/rubbycop/cop/style/variable_interpolation.rb, line 25 def check_for_interpolation(node) var_nodes(node.children).each do |v| var = v.source add_offense(v, :expression, format(MSG, var, var)) end end
var_nodes(nodes)
click to toggle source
# File lib/rubbycop/cop/style/variable_interpolation.rb, line 38 def var_nodes(nodes) nodes.select { |n| n.variable? || n.reference? } end