From: "matz (Yukihiro Matsumoto)" Date: 2021-12-09T07:58:17+00:00 Subject: [ruby-core:106577] [Ruby master Feature#12084] `Class#instance` Issue #12084 has been updated by matz (Yukihiro Matsumoto). * `instance` is NG. For example, `Array.instance => nil` is confusing * `attached_object` is better, at least for singleton classes. But there's still no real-world use-case. For your information, `NilClass` is not a singleton class. It's a class with only an instance. This is side evidence of this method is confusing. Even the original proposer can misunderstand the concept. Matz. ---------------------------------------- Feature #12084: `Class#instance` https://bugs.ruby-lang.org/issues/12084#change-95240 * Author: sawa (Tsuyoshi Sawada) * Status: Open * Priority: Normal ---------------------------------------- For meta-programming/debugging purposes, I would like to request the inverse of `Object#singleton_class`. Namely, a method that is called on a class that is a singleton class, and returns the object it is a singleton of. Since the `Singleton` module in the standard library http://ruby-doc.org/stdlib-2.3.0/libdoc/singleton/rdoc/Singleton.html assigns the method name `instance` to such classes, I think `Class#instance` should be the name for such feature. ~~~RUBY Array.singleton_class.instance # => Array "foo".singleton_class.instance # => "foo" ~~~ When the receiver is a class but is not a singleton class, then it should raise an error. ~~~RUBY Array.instance # => error ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: