class RuboCop::Cop::Style::VariableInterpolation
Checks for variable interpolation (like “#@ivar”).
@example
# bad "His name is #$name" /check #$pattern/ "Let's go to the #@store" # good "His name is #{$name}" /check #{$pattern}/ "Let's go to the #{@store}"
Constants
- MSG
Public Instance Methods
on_node_with_interpolations(node)
click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 25 def on_node_with_interpolations(node) var_nodes(node.children).each do |var_node| add_offense(var_node) do |corrector| corrector.replace(var_node, "{#{var_node.source}}") end end end
Private Instance Methods
message(range)
click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 35 def message(range) format(MSG, variable: range.source) end
var_nodes(nodes)
click to toggle source
# File lib/rubocop/cop/style/variable_interpolation.rb, line 39 def var_nodes(nodes) nodes.select { |n| n.variable? || n.reference? } end