I have a script that iterates using ObjectSpace#each_object
with no args. Then it prints how many instances exist for each class.
I realized that some
For the similar situation where you simply want a class you created that inherits from BasicObject
to support the #class
method, you can copy the method over from Kernel
.
class Foo < BasicObject
define_method(:class, ::Kernel.instance_method(:class))
end
f = Foo.new
puts f.class
=> Foo
(class << object; self; end).superclass