Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
ObjectSpace.internal_class_of
(untyped) -> ::Class
ObjectSpace.internal_class_of(obj) → class or module
ext/objspace/objspace.c
View on GitHub ↗
static VALUE
objspace_internal_class_of(VALUE self, VALUE obj)
{
VALUE klass;
if (rb_typeddata_is_kind_of(obj, &iow_data_type)) {
obj = (VALUE)DATA_PTR(obj);
}
if (RB_TYPE_P(obj, T_IMEMO)) {
return Qnil;
}
else {
klass = CLASS_OF(obj);
return wrap_klass_iow(klass);
}
}
Returns the real class of obj, which may differ from the class returned by Object#class.
Ruby inserts hidden classes into an object’s ancestry, such as a singleton class or an included module’s iclass. Object#class skips over these, but this method returns the first one, including any hidden class:
Example
require 'objspace' s = "x" def s.foo; end # gives +s+ a singleton class s.class # => String ObjectSpace.internal_class_of(s) # => #<Class:#<String:0x000000012574c1f8>>
obj may be an ObjectSpace::InternalObjectWrapper, in which case the class of the wrapped internal object is returned.
Note that you should not use this method in your application.
This method is only expected to work with C Ruby.
See also
.garbage_collect
.internal_super_of
.each_object
.memsize_of
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0