https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112020-02-07T12:48:37ZRuby Issue Tracking SystemRuby master - Feature #16615: Group style access scope for macroshttps://redmine.ruby-lang.org/issues/16615?journal_id=841952020-02-07T12:48:37Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>The suggestion is fairly short; might help to expand a bit, in particular why it would be<br>
necessary/useful.</p>
<p>Two comments from me in regards to the proposal:</p>
<ol>
<li>
<p>Is there a defining difference towards e. g. the attr* family? Perhaps I missed this<br>
in the proposal, but it should be remembered, even more so as this may become a question<br>
to newcomers for ruby - see the old questio about "Symbol versus String" and strange<br>
add-ons such as HashWithIndifferentAccess.</p>
</li>
<li>
<p>I believe the name "macro" is an awkward name. I am not sure that name should be added,<br>
but even more importantly the relatedness to 1) should be considered. (The public versus<br>
private distinction in ruby is not a strong one, due to ruby's dynamic nature and<br>
philosophy. I understand why the distinction is there, but personally I very, very<br>
rarely use public/private ever; if then mostly just to portray intention to others<br>
in a libary, but even then I often wonder whether this is even necessary. I think it<br>
then comes down a lot to the personal preferences of a given ruby user more than<br>
anything else.).</p>
</li>
</ol> Ruby master - Feature #16615: Group style access scope for macroshttps://redmine.ruby-lang.org/issues/16615?journal_id=842252020-02-11T18:15:57Zshan (Shannon Skipper)
<ul></ul><p>The idea of attrs returning a Symbol was rejected in: <a href="https://bugs.ruby-lang.org/issues/9453" class="external">https://bugs.ruby-lang.org/issues/9453</a></p>
<p>Your example doesn't seem to be a macro. How does this differ from attrs?</p> Ruby master - Feature #16615: Group style access scope for macroshttps://redmine.ruby-lang.org/issues/16615?journal_id=845032020-03-06T06:43:31Zted (Ted Johansson)drenmi@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/84503/diff?detail_id=56527">diff</a>)</li></ul> Ruby master - Feature #16615: Group style access scope for macroshttps://redmine.ruby-lang.org/issues/16615?journal_id=845042020-03-06T06:45:08Zted (Ted Johansson)drenmi@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/84504/diff?detail_id=56528">diff</a>)</li></ul> Ruby master - Feature #16615: Group style access scope for macroshttps://redmine.ruby-lang.org/issues/16615?journal_id=845052020-03-06T06:50:57Zted (Ted Johansson)drenmi@gmail.com
<ul></ul><p>shevegen (Robert A. Heiler) wrote in <a href="#note-1">#note-1</a>:</p>
<blockquote>
<p>Two comments from me in regards to the proposal:</p>
<ol>
<li>Is there a defining difference towards e. g. the attr* family? Perhaps I missed this<br>
in the proposal, but it should be remembered, even more so as this may become a question<br>
to newcomers for ruby - see the old questio about "Symbol versus String" and strange<br>
add-ons such as HashWithIndifferentAccess.</li>
</ol>
</blockquote>
<p>The <code>attr_*</code> family of methods currently enjoys special treatment here, as they are the only methods<br>
which define instance methods that will obey this style of visibility scope.</p>
<blockquote>
<ol start="2">
<li>I believe the name "macro" is an awkward name. I am not sure that name should be added,<br>
but even more importantly the relatedness to 1) should be considered.</li>
</ol>
</blockquote>
<p>I changed the name to a meta-syntactic variable, since it's irrelevant to the proposal itself.</p>
<blockquote>
<p>(The public versus private distinction in ruby is not a strong one, due to ruby's dynamic<br>
nature and philosophy. [...] I think it then comes down a lot to the personal preferences<br>
of a given ruby user more than anything else.).</p>
</blockquote>
<p>I think you might be projecting your personal opinion onto "Ruby in general". I can't think<br>
of any library which doesn't make extensive use of encapsulation. (For example, Rails has<br>
1,073 uses of <code>private</code>.) Not saying you have todo it in your projects, but it is a thing, and in my<br>
experience working with large code bases, it's also a Good Thing™. :-)</p> Ruby master - Feature #16615: Group style access scope for macroshttps://redmine.ruby-lang.org/issues/16615?journal_id=845562020-03-09T14:39:08ZDan0042 (Daniel DeLorme)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/84556/diff?detail_id=56557">diff</a>)</li></ul><p>Maybe a more concrete example would be helpful:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">def</span> <span class="nf">defc</span>
<span class="n">define_method</span><span class="p">(</span><span class="ss">:c</span><span class="p">){</span> <span class="p">}</span>
<span class="k">end</span>
<span class="k">class</span> <span class="nc">Foo</span>
<span class="kp">private</span>
<span class="k">def</span> <span class="nf">a</span><span class="p">;</span> <span class="k">end</span>
<span class="nb">attr_accessor</span> <span class="ss">:b</span>
<span class="n">defc</span>
<span class="k">end</span>
<span class="no">Foo</span><span class="p">.</span><span class="nf">new</span><span class="p">.</span><span class="nf">a</span> <span class="c1">#=> NoMethodError (private method `a' called)</span>
<span class="no">Foo</span><span class="p">.</span><span class="nf">new</span><span class="p">.</span><span class="nf">b</span> <span class="c1">#=> NoMethodError (private method `b' called)</span>
<span class="no">Foo</span><span class="p">.</span><span class="nf">new</span><span class="p">.</span><span class="nf">c</span> <span class="c1">#=> nil</span>
</code></pre>
<p>Having <code>c</code> be declared as private may be desirable... but there's sure to be a compatibility impact.</p>
<p>Is that why you added the condition that this should only happen if the meta-method (bar / defc) returns the instance method name (baz / c) as a symbol?</p>