Issue #11297 has been updated by Nobuyoshi Nakada.

Description updated

----------------------------------------
Feature #11297: Allow private method of self to be called
https://bugs.ruby-lang.org/issues/11297#change-53576

* Author: Soutaro Matsumoto
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Ruby does not allow private method to be called if receiver is given. Calling private method with receiver is prohibited even if it is written as self, though the fact that the receiver is self is still clear.

This ticket is to propose to allow the private method to be called if its receiver is written as self.

The following Ruby program is to explain my idea.

~~~ruby
class A
  private def f
  end
end

A.new.instance_eval do 
  f()              # Okay, without receiver
  self.f           # Currently NoMethodError, but should be okay in my opinion
  self.itself.f    # NoMethodError anyway; the receiver is not written as self
end
~~~

This change will allow to call private accessor method like `self.title=`.
It also will make refactoring to make a public method private easier. Currently, such kind of refactoring may require to rename duplicated local variables or add `()` to method calls.


---Files--------------------------------
private_with_self.diff (916 Bytes)


-- 
https://bugs.ruby-lang.org/