Project

General

Profile

Feature #18552

Updated by byroot (Jean Boussier) 5 months ago

Right now the only way to check wether an object has a singleton class is to do something akin to: 

 ```c 
 !SPECIAL_CONST(obj) && FL_TEST(RBASIC(obj)->klass, FL_SINGLETON); 
 ``` 

 Which doesn't does seem very clean. 

 ### Use case 

 This came up in `msgpack`. The library have a registry of serializers on a per class basis, and wish to support singleton classes too. 
 So it is calling `rb_singleton_class()` which cause lots of useless singleton classes to be created: https://github.com/msgpack/msgpack-ruby/pull/245 


 ### Proposed patch 

 https://github.com/ruby/ruby/pull/5499

Back