Project

General

Profile

Actions

Bug #16947

closed

private method unexpected behavior

Added by kapitan_morgan (Yaromir Bartosh) almost 4 years ago. Updated almost 4 years ago.

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

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
Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

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

Updated by kapitan_morgan (Yaromir Bartosh) almost 4 years 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
Actions #3

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

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

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Status changed from Open to Closed

It is allowed since 2.7.0.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0