- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
Provide a way to declare visibility of attributes defined by attr* methods in a single expression #3757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Could you please create an issue on bugs.ruby-lang.org ? I'll even second your request | 
| I've already created issue but I forgot to post it here. Thanks for reminding me. | 
| Great news, this was accepted by Matz 🎉 Missing from the PR: 
 Did you want to amend this PR and do you have time to do it quickly? Otherwise we can merge this and add the rest in another commit. | 
| This is great news! 
 It is covered in this PR. Am I missing something? 
 I will add this. | 
| 
 My mistake 🤦♂️ 
 Thanks! Also missing, if you want to add: entries in  | 
a9a7726    to
    9611e94      
    Compare
  
    | @marcandre I pushed 2 commits (I will squash all of them when this PR will satisfy all requirements) with following changes: 
 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick changes.
I checked more closely the doc and there are some updates to do...
| @marcandre Thank you for review. I made all requested changes. Additionaly I added rdoc for returned type to  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I need sleep; maybe others will have a look, otherwise I intend to commit in a day or two...
| Thanks for your assist. Should I squash commits or will it be done during merging? | 
| Oh, I got distracted, sorry. Could you please squash your commits and rebase to resolve the conflict with NEWS? | 
624f012    to
    67a4651      
    Compare
  
    | No problem. I've just done it. | 
| Merged, thank you for the PR and your prompt updates  | 
| Hi, Unfortunately, a CI (Solaris10 with gcc) started failing randomly after this commit 81739ad. http://rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/recent.html I'm now investigating the issue on the CI environment, but I have not been able to reproduce this issue manually. As far as I see, the commit itself looks benign, but to isolate the problem, I may revert the commit temporarily. Thank you for your understanding. | 
| Oh, interesting. I'm curious to see what could possible cause this in the commit. Thank you so much for looking into it @mame | 
| I've reverted the commit 81739ad and related ones (34f0606, e042e84, and 66090b9), and now the CI succeeded. http://rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20201218T080004Z.fail.html.gz The failure is flaky, so I'll watch a few successive builds. I guess this changeset may include something bad, though I can't find offhand... I'll check it deeply tonight. | 
| If possible, it would be helpful to split the changeset to each part (making  | 
| @mame Will it be sufficient if I split this PR into multiple commits? Or should I commit only 1 change, wait for CI, commit 2nd change, wait for CI and so on? Also, should it be done in this PR (which is already merged) or create new one? | 
| The CI build has been executed six times since I reverted, and no failure occurred so far. So, I think this PR includes something bad. However, I've gone through this PR and I couldn't find any wrong code. Solaris 10 uses GCC 4 which is very old, so it might accidentally trigger a compiler bug, but I'm unsure. 
 I think this approach is good. Could you please create a new PR for one change (whichever you like)? Thank you for your ooperation. | 
| Ok, no problem. I created new PR#3934 and will push each change as separate commit to find out which one fails on CI. | 

Description
Many of us (me included) declare class attributes, even if they are private, on the top of class definition. When reading source code it's convinient to see what kind of attributes class has.
To declare private attributes we can:
attr*methods and later change visiblity callingprivateprivatewithout argument, then declare attributes and finally call (in most cases)publicto keep defining public methodsTo simplify it and create other possibilites I propose to:
attr*methods so as they return array of defined methods namespublic/protected/privatemethods to receive array of methods names (single argument)With requested feature we could write code like this:
Additionaly you could use
attr*with your own methods. Something like this:Backward compatibility
attr*methods currently returnnilso there should be no problem with changing thempublic/protected/privatemethods receive multiple positional arguments and convert all non symbol/string objects to strings. I can imagine only one case where compatibility would be broken:Currently
[[:foo], [:bar]]would be displayed,[[:bar], [:foo]]after requested feature is implemented.