https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112014-07-31T16:21:33ZRuby Issue Tracking SystemRuby master - Bug #10103: Unable to refine class with CONSTANThttps://redmine.ruby-lang.org/issues/10103?journal_id=481512014-07-31T16:21:33Zengineersmnky (Mike Hein)engineersmnky@gmail.com
<ul></ul><p>I would like to also mention that this impacts class_variables as well</p>
<pre><code> module Foobar
@@baz = "boom"
refine String do
@@foo = "bar"
def foobar
@@foo
end
def bazical
@@baz
end
end
end
using Foobar
Foobar.class_variables #=> [:@@baz, :@@foo]
"".bazical #=> "boom"
"".foobar #=> "bar"
</code></pre>
<p>The first one I understand since the block can utilize variables and methods outside of itself. The second one really confuses me as I didn't expect it to skip over String and end up in Foobar. It also does not raise any warning about <code>warning: class variable access from toplevel</code>. Just as I would have expected constants to raise a <code>SyntaxError</code> for dynamic assignment. Instance variables seem to be ignored all together from what I can see.</p> Ruby master - Bug #10103: Unable to refine class with CONSTANThttps://redmine.ruby-lang.org/issues/10103?journal_id=481582014-08-01T15:17:11Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Constants (and class variables) are not included in refinement modification. Constants still belong to outer class.<br>
If we change this, we have to make incompatible change to constant scoping rules.<br>
I don't think its wise.</p>
<p>But maybe above class variables case should be warned, probably.</p>
<p>Matz.</p> Ruby master - Bug #10103: Unable to refine class with CONSTANThttps://redmine.ruby-lang.org/issues/10103?journal_id=604032016-09-07T07:41:08Zshugo (Shugo Maeda)
<ul><li><strong>Assignee</strong> set to <i>shugo (Shugo Maeda)</i></li></ul> Ruby master - Bug #10103: Unable to refine class with CONSTANThttps://redmine.ruby-lang.org/issues/10103?journal_id=604302016-09-08T04:44:56Zshugo (Shugo Maeda)
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul><p>Applied in changeset r56101.</p>
<hr>
<ul>
<li>insns.def (setclassvariable, setconstant): warn when self is a<br>
refinement. [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Unable to refine class with CONSTANT (Closed)" href="https://redmine.ruby-lang.org/issues/10103">#10103</a>] <a href="https://blade.ruby-lang.org/ruby-core/64143">[ruby-core:64143]</a></li>
</ul>