Project

General

Profile

Actions

Feature #11297

closed

Allow private method of self to be called

Added by soutaro (Soutaro Matsumoto) almost 9 years ago. Updated over 4 years ago.

Status:
Closed
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 2 (0 open2 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0