diff options
author | Ufuk Kayserilioglu <ufuk@paralaus.com> | 2022-09-27 01:19:22 +0300 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2022-10-20 17:30:17 +0200 |
commit | 0378e2f4a8319440dd65c82b16f189161472d237 (patch) | |
tree | 6c2c6dd91c624fd4ae6ad4be5dd3a6d04528df37 /test | |
parent | 192bc725290ca4b271bff2bae6123d84c25f7173 (diff) |
Add Class#attached_object
Implements [Feature #12084]
Returns the object for which the receiver is the singleton class, or
raises TypeError if the receiver is not a singleton class.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6450
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_class.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 07c34ce9d5..8d9fde144e 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -759,6 +759,31 @@ class TestClass < Test::Unit::TestCase end end + def test_attached_object + c = Class.new + sc = c.singleton_class + obj = c.new + + assert_equal(obj, obj.singleton_class.attached_object) + assert_equal(c, sc.attached_object) + + assert_raise_with_message(TypeError, /is not a singleton class/) do + c.attached_object + end + + assert_raise_with_message(TypeError, /`NilClass' is not a singleton class/) do + nil.singleton_class.attached_object + end + + assert_raise_with_message(TypeError, /`FalseClass' is not a singleton class/) do + false.singleton_class.attached_object + end + + assert_raise_with_message(TypeError, /`TrueClass' is not a singleton class/) do + true.singleton_class.attached_object + end + end + def test_subclass_gc c = Class.new 10_000.times do |