Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Object#singleton_class
obj.singleton_class → class
object.c
View on GitHub ↗
static VALUE
rb_obj_singleton_class(VALUE obj)
{
return rb_singleton_class(obj);
}
Returns the singleton class of obj. This method creates a new singleton class if obj does not have one.
If obj is nil, true, or false, it returns NilClass, TrueClass, or FalseClass, respectively. If obj is an Integer, a Float or a Symbol, it raises a TypeError.
Example
Object.new.singleton_class #=> #<Class:#<Object:0xb7ce1e24>> String.singleton_class #=> #<Class:String> nil.singleton_class #=> NilClass
See also
#send
#singleton_method
#respond_to_missing?
#singleton_methods
also in
4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0