Actions
Bug #20943
openConstant defined in `Data.define` block
Description
From https://github.com/ruby/ruby/pull/12274:
A couple times in code review I've seen constants inadvertently leak to top level from within a
Struct
orData
do block. I think it would be nice to show reopening theData
class when a constant is defined, so the constant is defined within the namespace. In this case,Measure::NONE
instead of top levelObject::NONE
. It would also show readers that it's okay to reopen aData
class, which seems nice since some folk might not realize. Thanks for considering!
However, I think that NONE
probably might be intended to be defined under Measure
.
Current:
Measure = Data.define(:amount, :unit) do
NONE = Data.define
end
p NONE #=> NONE
Another:
Measure = Data.define(:amount, :unit) do
NONE = Data.define
p NONE #=> Measure::NONE
end
p NONE # uninitialized constant NONE (NameError)
@zverok (Victor Shepelev) How do think?
Actions
Like0
Like0Like0Like0Like0Like0Like0