Project

General

Profile

Actions

Feature #18552

closed

Expose `VALUE rb_singleton_class_get(VALUE)` to extensions

Added by byroot (Jean Boussier) about 2 years ago. Updated about 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:107301]

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

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0