From: santiago@wyeworks.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:68502] [Ruby trunk - Bug #10967] [Open] Is "warning: private attribute?" wrong?
Date: Wed, 11 Mar 2015 20:06:42 +0000 [thread overview]
Message-ID: <redmine.issue-10967.20150311200640.5b460ef227439a16@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-10967.20150311200640@ruby-lang.org
Issue #10967 has been reported by Santiago Pastorino.
----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967
* Author: Santiago Pastorino
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The following code ...
```
class Y
def initialize
@x = "ZOMG"
end
def print_x
puts x
end
private
attr_reader :x
end
Y.new.print_x
```
outputs ...
```
test.rb:12: warning: private attribute?
```
I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.
Also this code ...
```
class Y
def initialize
@x = "ZOMG"
end
def print_x
puts x
end
def assign_x
self.x = "ZOMG ZOMG"
end
private
attr_accessor :x
end
y = Y.new
y.assign_x
y.print_x
```
Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.
So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.
--
https://bugs.ruby-lang.org/
next parent reply other threads:[~2015-03-11 20:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
2015-03-11 20:06 ` santiago [this message]
2015-03-12 15:03 ` [ruby-core:68510] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong? santiago
2015-03-28 8:36 ` [ruby-core:68667] Re: [Ruby trunk - Bug #10967] [Open] " Zachary Scott
2015-04-27 22:42 ` [ruby-core:69005] [Ruby trunk - Bug #10967] " nobu
2015-04-28 0:25 ` [ruby-core:69007] " ruby-core
2015-04-30 18:23 ` [ruby-core:69042] " santiago
2015-05-14 7:00 ` [ruby-core:69186] " matz
2015-06-30 4:18 ` [ruby-core:69804] " usa
2015-07-03 8:33 ` [ruby-core:69851] " usa
2015-08-14 6:45 ` [ruby-core:70383] " nagachika00
2015-08-17 8:53 ` [ruby-core:70419] " usa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-10967.20150311200640.5b460ef227439a16@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).