Project

General

Profile

Actions

Bug #20643

closed

Ruby 3.2 behavior change for protected and private methods when yield self

Added by tatethurston (Tate Thurston) 6 days ago. Updated 6 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.4 (2024-04-23 revision af471c0e01) [arm64-darwin23]
[ruby-core:118642]

Description

I noticed the following behavior change when updating my application from Ruby 3.1 to Ruby 3.2. Using the following code:

class Foo

  def try
    yield self
  end

  private

  def bar
    puts "private method bar called"
  end
end

Foo.new.try(&:bar)

Under 3.1 (ruby 3.1.6p260 (2024-05-29 revision a777087be6) [arm64-darwin23])

private method bar called
=> nil

Under Ruby 3.2 (ruby 3.2.4 (2024-04-23 revision af471c0e01) [arm64-darwin23])

(irb):4:in `try': private method `bar' called for #<Foo:0x000000010770a578> (NoMethodError)
        from (irb):14:in `<main>'
        from /Users/tatthurs/.asdf/installs/ruby/3.2.4/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
        from /Users/tatthurs/.asdf/installs/ruby/3.2.4/bin/irb:25:in `load'
        from /Users/tatthurs/.asdf/installs/ruby/3.2.4/bin/irb:25:in `<main>'
irb(main):015:0>

Is this change expected? I could not find a note in the changelog.

Updated by jeremyevans0 (Jeremy Evans) 6 days ago

  • Status changed from Open to Closed

It is expected, see #18826. As it was a bug fix and not a new feature, it wasn't mentioned in NEWS, though I can see it causing problems for code that relied on the previous behavior.

Updated by tatethurston (Tate Thurston) 6 days ago

jeremyevans0 (Jeremy Evans) wrote in #note-1:

It is expected, see #18826. As it was a bug fix and not a new feature, it wasn't mentioned in NEWS, though I can see it causing problems for code that relied on the previous behavior.

Awesome, thank you.

Actions

Also available in: Atom PDF

Like0
Like1Like0