From: eregontp@... Date: 2014-11-08T21:31:03+00:00 Subject: [ruby-core:66149] [ruby-trunk - Bug #9907] Abbreviated method assignment with private attr_writer/attr_reader does not work. Issue #9907 has been updated by Benoit Daloze. Until now, the ability to call private methods has always been a property verifiable at parse time (no receiver or "receiver is self and methods ends with ="). I think it is good to remain that way so it is really easy to know whether you may call private method, as a Ruby user. So I think the "o" cases above should not be able to call private methods. On the other hand, the current semantics seem less clear and more complex than they could be. I agree with Charles, the "no explicit receiver or receiver is literally `self`" rule is simpler, more consistent and avoid problems with special cases such as assignments. Having a hidden implicit visibility such as in the committed change seems harder for everyone to understand and may only solve a part of the special cases. ---------------------------------------- Bug #9907: Abbreviated method assignment with private attr_writer/attr_reader does not work. https://bugs.ruby-lang.org/issues/9907#change-49852 * Author: J��rg W Mittag * Status: Closed * Priority: Normal * Assignee: * Category: core * Target version: current: 2.2.0 * ruby -v: ruby 2.2.0dev (2014-06-05 trunk 46357) [x86_64-darwin13] * Backport: 2.0.0: REQUIRED, 2.1: DONTNEED ---------------------------------------- This looks like a hole in the specification: ~~~ruby private def foo=(*) end public def foo; 0 end self.foo = 42 self.foo += 42 # private method `foo=' called for main:Object (NoMethodError) private :foo self.foo += 42 # private method `foo' called for main:Object (NoMethodError) ~~~ There is an exception for `private` writers in the rule for private message sends, but apparently that exception needs to broadened so that it also works in the case of abbreviated assignments. I'm not entirely sure what this rule would be, but I don't think it would break backwards compatibility, since all situations that would work differently with the changed rule would currently raise a `NoMethodError` anyway. The rule should be something like: > * `private` methods can only be called without an explicit receiver. > * An exception is made for method assignments, where the literal receiver `self` is also allowed in the assignee method expression. > * This also applies to compound assignments: `self.foo ��= bar` shall *always* succeed if either or both of `foo` and `foo=` are `private`. -- https://bugs.ruby-lang.org/