Actions
Feature #18552
closedExpose `VALUE rb_singleton_class_get(VALUE)` to extensions
Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Description
Right now the only way to check wether an object has a singleton class is to do something akin to:
!SPECIAL_CONST(obj) && FL_TEST(RBASIC(obj)->klass, FL_SINGLETON);
Which doesn't 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¶
Actions