class RuboCop::Cop::Lint::ShadowingOuterLocalVariable
end
end
do_something(bar)
2.times do |bar|
foo = 1
def some_method
# good
@example
end
end
do_something(foo)
2.times do |foo| # shadowing outer ‘foo`
foo = 1
def some_method
# bad
@example
end
Ractor.new(worker_id, pipe) do |worker_id, pipe|
worker_id, pipe = env
eg. following style is encouraged:
because `Ractor` should not access outer variables.
NOTE: Shadowing of variables in block passed to `Ractor.new` is allowed
“shadowing outer local variable - foo”.
given by `ruby -cw` prior to Ruby 2.6:
in block arguments or block-local variables. This mirrors the warning
This cop checks for the use of local variable names from an outer scope
def self.joining_forces
def self.joining_forces VariableForce end
def before_declaring_variable(variable, variable_table)
def before_declaring_variable(variable, variable_table) return if variable.should_be_unused? return if ractor_block?(variable.scope.node) outer_local_variable = variable_table.find_variable(variable.name) return unless outer_local_variable message = format(MSG, variable: variable.name) add_offense(variable.declaration_node, message: message) end