Project

General

Profile

Actions

Bug #10901

closed

Object#singleton_methods behaves differently depending on whether the singleton_class exists

Added by bughit (bug hit) about 9 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
[ruby-core:68289]

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

singleton-class-singleton-methods.patch (2.09 KB) singleton-class-singleton-methods.patch jeremyevans0 (Jeremy Evans), 07/08/2019 01:00 AM
Actions #1

Updated by bughit (bug hit) about 9 years ago

Is this a bug, and if not, why?

Updated by jeremyevans0 (Jeremy Evans) almost 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.

Actions #3

Updated by jeremyevans (Jeremy Evans) over 4 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]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0