https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-11-30T22:51:38ZRuby Issue Tracking SystemRuby master - Bug #7475: Unexpected behavior of Module#append_features on singleton classhttps://bugs.ruby-lang.org/issues/7475?journal_id=342212012-11-30T22:51:38Zernie (Ernie Miller)ernie@erniemiller.org
<ul></ul><p>Another quick set of observations from this morning:</p>
<pre><code>class Baz
class << self
Const = 'Const'
@@foo = 'foo'
end
end
Baz.class_variables.inspect # => [:@@foo]
Baz.singleton_class.class_variables.inspect # => []
Baz.singleton_class.class_variable_get :@@foo # => 'foo' ???
Baz.const_get(:Const, false) rescue "Nope." # => 'Nope.'
Baz.singleton_class.const_get(:Const, false) rescue "Nope." # => Const
# Let's try setting it explicitly.
Baz.singleton_class.class_variable_set :@@foo, 'foo'
Baz.singleton_class.class_variables.inspect # => [] -- still "empty"
</code></pre>
<p>However, if we extend Foo on Baz, vs opening the singleton class with "class << self", we can class_variable_set on the singleton and see it show up in the list of class variables, vs being empty.</p>
<p>All of this is to say that I think some unexpected weirdness is going on in rb_include_module and/or include_class_new.</p> Ruby master - Bug #7475: Unexpected behavior of Module#append_features on singleton classhttps://bugs.ruby-lang.org/issues/7475?journal_id=364582013-02-18T08:48:44Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li><li><strong>Target version</strong> changed from <i>1.9.3</i> to <i>2.6</i></li></ul><p>Matz, could you check it?</p> Ruby master - Bug #7475: Unexpected behavior of Module#append_features on singleton classhttps://bugs.ruby-lang.org/issues/7475?journal_id=364802013-02-18T10:47:48Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/36480/diff?detail_id=25953">diff</a>)</li></ul> Ruby master - Bug #7475: Unexpected behavior of Module#append_features on singleton classhttps://bugs.ruby-lang.org/issues/7475?journal_id=688512017-12-25T18:15:09Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>2.6</i></del>)</li></ul> Ruby master - Bug #7475: Unexpected behavior of Module#append_features on singleton classhttps://bugs.ruby-lang.org/issues/7475?journal_id=807792019-08-15T15:28:44Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>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):</p>
<ul>
<li>Singleton Class (A.singleton_class)</li>
<li>All Ancestors of Class (A.ancestors)</li>
</ul>
<p>Note that this does not include modules included in the singleton class.</p>
<p>Class variable access is different for singleton classes because class variable access from the singleton class should access class variables in the class itself.</p>
<p>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 <code>Class</code>. Please submit a feature request if you would like to change class variable lookup.</p>