https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112014-02-03T15:05:38ZRuby Issue Tracking SystemRuby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=448962014-02-03T15:05:38Zjballanc (Joshua Ballanco)jballanc@gmail.com
<ul></ul><p><em>bump</em></p>
<p>Would be nice if we could get this in 2.2 (if someone could update the target version, I'd appreciate it).</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=448972014-02-03T15:13:24ZEregon (Benoit Daloze)
<ul></ul><pre><code>private *attr_reader(:images, :key_map, :window, :screen_manager, :animations)
</code></pre>
<p>does not look so nice to me (the parens and the explicit splat).<br>
Maybe #private should accept an Array of Symbols so:</p>
<pre><code>private attr_reader :images, :key_map, :window, :screen_manager, :animations
</code></pre>
<p>If there are so much ":", it might also be worth using %i:</p>
<pre><code>private attr_reader %i[images key_map window screen_manager animations]
</code></pre>
<p>but then attr_reader would also need to accept an Array of Symbols.</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=448982014-02-03T18:44:01Zsawa (Tsuyoshi Sawada)
<ul></ul><p>What is the point of defining a private accessor method? You can directly refer to the instance variables without using accessors.</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=449052014-02-04T05:22:31Zavdi (Avdi Grimm)avdi@avdi.codes
<ul></ul><p>There are a number of reasons I use them, but the most obvious is that a<br>
misspelled accessor method will raise NoMethod error, whereas a misspelled<br>
@ivar reference will silently return nil.</p>
<p>--<br>
Avdi Grimm<br>
<a href="http://avdi.org" class="external">http://avdi.org</a></p>
<p>I only check email twice a day. to reach me sooner, go to<br>
<a href="http://awayfind.com/avdi" class="external">http://awayfind.com/avdi</a></p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=449142014-02-05T00:27:11Zjballanc (Joshua Ballanco)jballanc@gmail.com
<ul></ul><p>Tsuyoshi Sawada wrote:</p>
<blockquote>
<p>What is the point of defining a private accessor method? You can directly refer to the instance variables without using accessors.</p>
</blockquote>
<p>The example I gave was just one case of "code in the wild" that would benefit from this change. Undoubtedly, as more people begin to take advantage of the ability to build method decorators (now that method definitions return something other than <code>nil</code>), having the attr* family of methods return something meaningful will mean that they can also benefit from these decorators.</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=459662014-03-27T17:13:15Zjballanc (Joshua Ballanco)jballanc@gmail.com
<ul></ul><p>It's been almost 2 months...any chance we could get a comment on this from the core team?</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=459812014-03-28T15:55:51Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=459912014-03-29T14:58:15Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>I am not positive. The example</p>
<p>private *attr_reader(:images, :key_map, :window, :screen_manager,:animations)</p>
<p>is not really intuitive. Besides that, you can define private_attr_reader, etc. by yourself.<br>
In that case, the code will be</p>
<p>private_attr_reader :images, :key_map, :window, :screen_manager,:animations</p>
<p>and looks much better.</p>
<p>Matz</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=461862014-04-11T19:48:21Ztrans (Thomas Sawyer)
<ul></ul><p>Letting #private accept an Array seems more preferable then adding yet another <del>method</del> slew of methods: <code>private_attr_writer</code>, <code>private_attr_accessor</code>, <code>protected_attr_reader</code>, <code>protected_attr_writer</code>, <code>protected_attr_accessor</code>, ...</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=461882014-04-12T01:31:11Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Thomas, private method that accept an array for methods names would be an interesting idea worth discussion.<br>
But it is different issue.</p>
<p>Matz.</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=482632014-08-08T22:38:43Znerdrew (Andrew Lazarus)nerdrew@gmail.com
<ul></ul><p>Chaining the two suggestions leads to a nice syntax (in my opinion):</p>
<p><code>private attr_reader :name, :address, :etc</code></p>
<p><code>private</code> needs to accept an array and <code>attr_*</code> needs to return its list (as an array) of arguments.</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=634262017-03-11T05:43:09Zvais (Vais Salikhov)vsalikhov@gmail.com
<ul></ul><p><code>attr_*</code> methods returning <code>nil</code> should be considered a bug at this point, since all other ways of defining methods return a symbol. This makes Ruby inconsistent, and violates its own Principle of Least Surprise.</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=642872017-04-17T08:29:04Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Yes, <code>def</code> and <code>define_method</code> returns symbols now.<br>
But it does not mean <code>attr_*</code> should return symbols. Since they can define multiple methods.<br>
Considering there's no use for private attributes, I don't think the proposal creates real-world value.</p>
<p>Besides that, mention to the principle of least surprise gives you negative evaluation here (since the background varies from user to user, and it does not lead to constructive discussion).</p>
<p>Matz.</p> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=648032017-05-14T04:50:05Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/13560">Feature #13560</a>: Module#attr_ methods return reasonable values</i> added</li></ul> Ruby master - Feature #9453: Return symbols of defined methods for `attr` and friendshttps://bugs.ruby-lang.org/issues/9453?journal_id=808432019-08-19T01:54:29Zznz (Kazuhiro NISHIYAMA)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/11541">Feature #11541</a>: Let attr_accessor, _reader & _writer return symbols of the defined methods</i> added</li></ul>