diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-08-09 16:44:43 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-09-21 16:10:18 -0700 |
commit | 7470f965650bf17875632f0c5f9e5a4d9de9fc3f (patch) | |
tree | ca40dbb76456ff9ff7a69bc5b6b5a02a494f4b43 /variable.c | |
parent | 5cb283217b713605c6bddc527f96bbc773fd1fb9 (diff) | |
download | ruby-7470f965650bf17875632f0c5f9e5a4d9de9fc3f.tar.gz |
Fix Module#class_variables for singleton classes of classes/modules
Module#class_variables should reflect class variable lookup. For
singleton classes of classes/modules, this means the lookup should
be:
* Singleton Class
* Class
* All Ancestors of Class
Note that this doesn't include modules included in the singleton
class, because class variable lookup doesn't include those.
Singleton classes of other objects do not have this behavior and
always just search all ancestors of the singleton class, so do not
change the behavior for them.
Fixes [Bug #8297]
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/variable.c b/variable.c index f3d73fac63..1627467bd9 100644 --- a/variable.c +++ b/variable.c @@ -3209,6 +3209,12 @@ static void* mod_cvar_of(VALUE mod, void *data) { VALUE tmp = mod; + if (FL_TEST(mod, FL_SINGLETON)) { + if (rb_namespace_p(rb_ivar_get(mod, id__attached__))) { + data = mod_cvar_at(tmp, data); + tmp = cvar_front_klass(tmp); + } + } for (;;) { data = mod_cvar_at(tmp, data); tmp = RCLASS_SUPER(tmp); |