Yukihiro Matsumoto wrote:
It changes the concept of private methods a little. It's OK to merge the patch if the document is updated at the same time..
It does change it, but it makes it much simpler in my opinion. It is basically "the receiver is statically the explicit literal special variable self
or implicit." This gets rid of the current exception for private writer methods (self.foo = bar
).
It also resolves the problems with private operator methods (self + bar
) and compound assignments with private writers and/or private operators (self += bar
, self.foo += bar
, where either +
or foo=
or both are private). It removes pretty much all edge cases in one blow.
See also #9907 which would be simplified by this proposal. In particular, implementing the simple rule would make Charles Oliver Nutter's confusion go away (#9907-6, #9907-8), be consistent with Nobuyoshi Nakada's expectations (#9907-7) and alleviate Benoit Daloze's concerns about being decidable statically at parse time (#9907-9).
In fact, I believe that with this feature all of these should work:
#!/usr/bin/env ruby
class Private
def doit
self.foo = self
self.foo **= self
self.foo *= self
self.foo /= self
self.foo %= self
self.foo += self
self.foo -= self
self.foo <<= self
self.foo >>= self
self.foo &= self
self.foo |= self
self.foo ^= self
self.foo &&= self
self.foo ||= self
!self
~self
+self
self ** self
-self
self * self
self / self
self % self
self + self
self - self
self << self
self >> self
self & self
self | self
self ^ self
self < self
self <= self
self >= self
self > self
self == self
self === self
self != self
self =~ self
self !~ self
self <=> self
self[self, self]
self[self, self] = self, self
self.(self, self)
end
private
attr_accessor :foo
def !(*args) p __method__, *args end
def ~(*args) p __method__, *args end
def +@(*args) p __method__, *args end
def **(*args) p __method__, *args end
def -@(*args) p __method__, *args end
def *(*args) p __method__, *args end
def /(*args) p __method__, *args end
def %(*args) p __method__, *args end
def +(*args) p __method__, *args end
def -(*args) p __method__, *args end
def <<(*args) p __method__, *args end
def >>(*args) p __method__, *args end
def &(*args) p __method__, *args end
def |(*args) p __method__, *args end
def ^(*args) p __method__, *args end
def <(*args) p __method__, *args end
def <=(*args) p __method__, *args end
def >=(*args) p __method__, *args end
def >(*args) p __method__, *args end
def ==(*args) p __method__, *args end
def ===(*args) p __method__, *args end
def !=(*args) p __method__, *args end
def =~(*args) p __method__, *args end
def !~(*args) p __method__, *args end
def <=>(*args) p __method__, *args end
def [](*args) p __method__, *args end
def []=(*args) p __method__, *args end
def call(*args) p __method__, *args end
end
Private.new.doit