Project

General

Profile

Feature #11297

Allow private method of self to be called

Added by soutaro (Soutaro Matsumoto) about 5 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:69711]

Description

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.

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) private_with_self.diff soutaro (Soutaro Matsumoto), 06/23/2015 01:15 PM

Related issues

Related to Ruby master - Bug #16947: private method unexpected behaviorClosedActions
Has duplicate Ruby master - Feature #16123: Allow calling a private method with `self.`ClosedActions

Also available in: Atom PDF