From: "Dan0042 (Daniel DeLorme)" Date: 2022-07-31T12:03:10+00:00 Subject: [ruby-core:109392] [Ruby master Feature#18930] Officially deprecate class variables Issue #18930 has been updated by Dan0042 (Daniel DeLorme). Eregon (Benoit Daloze) wrote in #note-8: > ```ruby > class A > @@foo = 1 > > def self.foo > @@foo > end > end > > class B < A > @@foo = 2 # actually writes in A > end > > p A.foo # => 2, but should be 1 > ``` This is exactly the behavior that I want and expect from class variables. If I wanted one 'foo' per subclass I would use class instance variables. It's not like I use class variables all *that* often, but I do use them more than global variables. So does that mean we should deprecate global variables? Class variables have their uses, and deprecating them is just removing a tool from the programmer's toolbox. Patronizing and disempowering. ---------------------------------------- Feature #18930: Officially deprecate class variables https://bugs.ruby-lang.org/issues/18930#change-98541 * 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: