[#106355] [Ruby master Bug#18373] RBS build failure: '/include/x86_64-linux/ruby/config.h', needed by 'constants.o'. — "vo.x (Vit Ondruch)" <noreply@...>
Issue #18373 has been reported by vo.x (Vit Ondruch).
28 messages
2021/12/01
[ruby-core:106587] [Ruby master Feature#12084] `Class#instance`
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-12-09 10:00:11 UTC
List:
ruby-core #106587
Issue #12084 has been updated by Eregon (Benoit Daloze). > 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. Interesting, I think what confuses people (including myself) is `nil.singleton_class # => NilClass`. And basically that's because `#singleton_class` has special behavior for true/false/nil (`special_singleton_class_of`). Such behavior is not used for any other Ruby value (the rest is TypeError or create a new anonymous singleton class). It's a bit funny too: ```ruby irb(main):002:0> TrueClass.singleton_class? => false irb(main):003:0> true.singleton_class.singleton_class? => false ``` It kind of makes sense given `TrueClass`, etc are defined as regular classes, and then creating an extra/separate singleton class would be confusing (methods could be defined on either). I guess it would be possible to create TrueClass as a singleton class (with superclass `Object`) and name it, but that's another proposal and the pros/cons are unclear to me at this stage. ---------------------------------------- Feature #12084: `Class#instance` https://bugs.ruby-lang.org/issues/12084#change-95251 * 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>