From: "matz (Yukihiro Matsumoto)" Date: 2022-01-31T02:55:40+00:00 Subject: [ruby-core:107381] [Ruby master Bug#11064] #singleton_methods for objects with special singleton_class returns an empty array Issue #11064 has been updated by matz (Yukihiro Matsumoto). `nil` does not have its singleton class, but `NilClass` plays the role of the singleton class (since `nil` is the only instance of `NilClass`). So a singleton method definition defines a method in `NilClass`. It's a kind of special treatment of singleton methods. Same for `true` and `false`. We have several options: * keep the behavior as it is, since `nil` does not have a singleton class * `nil.singleton_methods` should return methods defined in `NilClass` (same for `TrueClass` and `FalseClass`) Both have their own trade-offs. Either is OK for me but I slightly prefer the former, since it's easier. Matz. ---------------------------------------- Bug #11064: #singleton_methods for objects with special singleton_class returns an empty array https://bugs.ruby-lang.org/issues/11064#change-96283 * 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) #=> # NilClass.instance_methods.include? :bla #=> true # does not work nil.singleton_methods #=> [] ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: