From: "Eregon (Benoit Daloze)" Date: 2022-07-28T09:57:38+00:00 Subject: [ruby-core:109353] [Ruby master Feature#18930] Officially deprecate class variables Issue #18930 has been updated by Eregon (Benoit Daloze). For such a case it seems fine to use instance variables on the class and expose e.g. `SomeThingNeverInherited#some_config?`. If you don't want that to be public API it could be `:nodoc:` or made private + using `send`. ```ruby class SomeThingNeverInherited @some_config = :initial_value class << self def some_config=(value) @some_config = value end def some_config? @some_config end end def do_thing if SomeThingNeverInherited.some_config? do_one_thing else do_another_thing end end end SomeThingNeverInherited.new.do_thing ``` So I think it is fully actionable, even though it might require some thinking especially if inheritance is used, but then the actual semantics were very likely not the intended ones, so such thinking will actually fix bugs. ---------------------------------------- Feature #18930: Officially deprecate class variables https://bugs.ruby-lang.org/issues/18930#change-98497 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal ---------------------------------------- Ruby's class variables are very confusing, and it seem many people agree they should be avoided (#18927). How about we deprecate them officially? Concretely: * Mention in the documentation that class variables are deprecated and should be avoided/should not be used. * Add a parse-time deprecation warning, now that we only see those with `Warning[:deprecation] = true` it seems reasonable to add. -- https://bugs.ruby-lang.org/ Unsubscribe: