Bug #10901
closedObject#singleton_methods behaves differently depending on whether the singleton_class exists
Description
class Class1
def self.foo
end
end
c1 = Class1.new
instance_eigen = c1.singleton_class
p instance_eigen.singleton_methods(false)
instance_eigen.singleton_class
p instance_eigen.singleton_methods(false)
before the eigen exists, singleton_methods returns the methods on the superclass of the non existent eigen
after it's created singleton_methods returns []
The existence or non-existence of the eigen is an implementation detail that should not be exposed to the user, conceptually it always exists. So singleton_methods should treat a non existent eigen as an empty eigen, and not look to its superclass
Files
Updated by jeremyevans0 (Jeremy Evans) about 5 years ago
I think this is a bug and it should be fixed. Attached is a patch that fixes the issue by checking if the receiver is already a singleton class, and if so, calling rb_singleton_class
to force the creation of the singleton class of the singleton class.
Updated by jeremyevans (Jeremy Evans) about 5 years ago
- Status changed from Open to Closed
Applied in changeset git|9aba971e42c78bb9e446f28c0402bad55147a863.
Make Object#singleton_methods work correctly for singleton classes of objects
Fixes [Bug #10901]