Project

General

Profile

Bug #16947

private method unexpected behavior

Added by kapitan_morgan (Yaromir Bartosh) 3 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
[ruby-core:98707]

Description

private method called explicitly through self should return an error, but in version 2.7.1 an error does not occur and the method is executed


Files

private_method.rb (331 Bytes) private_method.rb example private method kapitan_morgan (Yaromir Bartosh), 06/10/2020 12:17 PM

Related issues

Related to Ruby master - Feature #11297: Allow private method of self to be calledClosedActions
Related to Ruby master - Feature #16123: Allow calling a private method with `self.`ClosedActions
#1

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Related to Feature #11297: Allow private method of self to be called added

Updated by kapitan_morgan (Yaromir Bartosh) 3 months ago

class Person
  def speak
    puts "Hey, Tj!"
  end

  def whisper_louder
    whisper
  end

  def whisper_self
    self.whisper
  end

  private 
  def whisper
    puts "His name's not really 'Tj'." 
  end 
end

p = Person.new

p.speak
p.whisper_louder

# should cause an error
# but in version 2.7.1 no error occurs
p.whisper_self
#3

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Related to Feature #16123: Allow calling a private method with `self.` added

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

It is allowed since 2.7.0.

Also available in: Atom PDF