[ruby-core:93599] [Ruby master Bug#10901] Object#singleton_methods behaves differently depending on whether the singleton_class exists
From:
merch-redmine@...
Date:
2019-07-08 01:01:04 UTC
List:
ruby-core #93599
Issue #10901 has been updated by jeremyevans0 (Jeremy Evans). File singleton-class-singleton-methods.patch added 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. ---------------------------------------- Bug #10901: Object#singleton_methods behaves differently depending on whether the singleton_class exists https://bugs.ruby-lang.org/issues/10901#change-79191 * Author: bughit (bug hit) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- ```ruby 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) -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>