From: merch-redmine@... Date: 2019-08-15T15:28:45+00:00 Subject: [ruby-core:94367] [Ruby master Bug#7475] Unexpected behavior of Module#append_features on singleton class Issue #7475 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Open to Closed I believe this is not a bug, it is expected behavior. Class variable lookup for singleton classes is different from regular classes. Class variable lookup for singleton classes is (with example class A): * Singleton Class (A.singleton_class) * All Ancestors of Class (A.ancestors) Note that this does not include modules included in the singleton class. Class variable access is different for singleton classes because class variable access from the singleton class should access class variables in the class itself. Class variable lookup could certainly be changed to include modules included in the singleton class, but that would be a separate feature request, and we would have to decide if we want to only include modules before the superclass's singleton class, or all modules and singleton classes before `Class`. Please submit a feature request if you would like to change class variable lookup. ---------------------------------------- Bug #7475: Unexpected behavior of Module#append_features on singleton class https://bugs.ruby-lang.org/issues/7475#change-80779 * Author: ernie (Ernie Miller) * Status: Closed * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: * ruby -v: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- =begin A more involved explanation is available at (()) In short, the handling of class variables (and constants) when a module is extended vs included is not as expected. Example: module Foo @@foo = 'foo' end class Bar include Foo end class Baz extend Foo end Bar.class_variable_get :@@foo # => "foo" Baz.singleton_class.class_variable_get :@@foo # => NameError: uninitialized class variable @@foo in Class We would expect constant and class variable lookup on the singleton class to work, but it doesn't. Both Rubinius and JRuby seem to behave as expected in this case. Thanks! =end -- https://bugs.ruby-lang.org/ Unsubscribe: