Closed
Description
Hi, I found an issue about Instance Variable Assumption that occurs when a class have a Struct
with its own initialize
method in its block.
Example code:
class Foo
Bar = Struct.new(:a) do
def initialize(a)
super
p 'bar created'
end
end
def initialize
@foo = :foo
end
def foo?
@foo == :foo
end
end
When I run reek
against this file, Reek reports a warning of Instance Variable Assumption
, even though @foo
in Foo
class is initialized correctly.
[1]:InstanceVariableAssumption: Foo assumes too much for instance variable '@foo' [https://github.com/troessner/reek/blob/v5.4.0/docs/Instance-Variable-Assumption.md]
It looks like the cause is Bar
which has a block containing an initialize
method.
I confirmed that Reek did not warn if:
Bar
does not have aninitialize
method.Bar
is defined by normal class syntax (class Bar ... end
).Bar
is defined after theinitialize
method ofFoo
.
Similar issue: #1137
Activity