From: "jeremyevans0 (Jeremy Evans) via ruby-core" Date: 2024-07-20T01:37:18+00:00 Subject: [ruby-core:118643] [Ruby master Bug#20643] Ruby 3.2 behavior change for protected and private methods when yield self Issue #20643 has been updated by jeremyevans0 (Jeremy Evans). 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. ---------------------------------------- Bug #20643: Ruby 3.2 behavior change for protected and private methods when yield self https://bugs.ruby-lang.org/issues/20643#change-109170 * Author: tatethurston (Tate Thurston) * Status: Closed * ruby -v: ruby 3.2.4 (2024-04-23 revision af471c0e01) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I noticed the following behavior change when updating my application from Ruby 3.1 to Ruby 3.2. Using the following code: ``` ruby 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 # (NoMethodError) from (irb):14:in `
' from /Users/tatthurs/.asdf/installs/ruby/3.2.4/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `' 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 `
' irb(main):015:0> ``` Is this change expected? I could not find a note in the changelog. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/