Actions
Bug #20643
closedRuby 3.2 behavior change for protected and private methods when yield self
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.4 (2024-04-23 revision af471c0e01) [arm64-darwin23]
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.
Actions
Like0
Like1Like0