[ruby-core:111391] [Ruby master Bug#11064] #singleton_methods for objects with special singleton_class returns an empty array

Issue #11064 has been updated by sawa (Tsuyoshi Sawada). Thank you, Matz for answering my question.
Singleton classes are in principle only accessed using the singleton_class method or the singleton class notation.
Since we already have the following results, ```ruby nil.singleton_class # => NilClass class << nil; self; end # => NilClass ``` the crucial part is that they should be the **only** way to access, if `NilClass` were to be a singleton class. So in short, the fact that it can be accessed directly through the name `NilClass` seems to be what is avoiding it from being a singleton class.
Implementation wise, FL_SINGLETON is set for singleton classes.
Thank you for letting me know about it. But I do not think Ruby users should need to worry too much about its implementation details. From the point of view of a user, that should be irrelevant for whether calling a class a singleton class or not. To summarize, it seems that just because `NiClass` has its name as a constant, it cannot be regarded as a singleton class. I now understand how the distinction is made currently, but I do not think it makes sense. I might make a feature request to get rid of this distinction. ---------------------------------------- Bug #11064: #singleton_methods for objects with special singleton_class returns an empty array https://bugs.ruby-lang.org/issues/11064#change-100766 * Author: rbjl (Jan Lelis) * Status: Open * Priority: Normal * ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- ~~~ def nil.bla 42 end # works nil.bla #=> 42 nil.singleton_method(:bla) #=> #<Method: NilClass#bla> NilClass.instance_methods.include? :bla #=> true # does not work nil.singleton_methods #=> [] ~~~ -- https://bugs.ruby-lang.org/
participants (1)
-
sawa (Tsuyoshi Sawada)