diff options
author | Jeremy Evans <[email protected]> | 2024-09-11 21:29:41 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2024-10-03 07:27:01 -0700 |
commit | 9986a7c3930437bc9d9b88736c22695585aa6c48 (patch) | |
tree | 1e62c79a403d7c6af31d5b17071d6f5995dccc5a /test/ruby | |
parent | dc83de49288d6da59fd8b13f701ac437e09f2d23 (diff) |
Make Object#singleton_method return methods in modules included in or prepended to singleton class
To simplify the implementation, this makes Object#singleton_method
call the same method called by Object#method (rb_obj_method), then
check that the returned Method is defined before the superclass of the
object's singleton class. To keep the same error messages, it rescues
exceptions raised by rb_obj_method, and then raises its own exception.
Fixes [Bug #20620]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11605
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_method.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index a7945082c2..ebe711ddb4 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -940,6 +940,38 @@ class TestMethod < Test::Unit::TestCase assert_raise(NameError, bug14658) {o.singleton_method(:bar)} end + def test_singleton_method_included_or_prepended_bug_20620 + m = Module.new do + extend self + def foo = :foo + end + assert_equal(:foo, m.singleton_method(:foo).call) + assert_raise(NameError) {m.singleton_method(:puts)} + + sc = Class.new do + def t = :t + end + c = Class.new(sc) do + singleton_class.prepend(Module.new do + def bar = :bar + end) + extend(Module.new do + def quux = :quux + end) + def self.baz = :baz + end + assert_equal(:bar, c.singleton_method(:bar).call) + assert_equal(:baz, c.singleton_method(:baz).call) + assert_equal(:quux, c.singleton_method(:quux).call) + + assert_raise(NameError) {c.singleton_method(:t)} + + c2 = Class.new(c) + assert_raise(NameError) {c2.singleton_method(:bar)} + assert_raise(NameError) {c2.singleton_method(:baz)} + assert_raise(NameError) {c2.singleton_method(:quux)} + end + Feature9783 = '[ruby-core:62212] [Feature #9783]' def assert_curry_three_args(m) |