[ruby-core:124734] [Ruby Feature#6478] BasicObject#__class__
Issue #6478 has been updated by Eregon (Benoit Daloze). In terms of naming I think `__class__` looks like a hack that Python would use and not Ruby-like. Why not add `BasicObject#class`? I think `Kernel.instance_method(:class).bind_call(o)` is fine for most cases. FWIW performance-wise on TruffleRuby there isn't much difference when storing the `UnboundMethod` in a constant: ``` truffleruby 33.0.1 (2026-01-20), like ruby 3.3.7, Oracle GraalVM Native [x86_64-linux] Calculating ------------------------------------- instance_method.bind_call 33.492M (± 3.0%) i/s (29.86 ns/i) - 169.962M in 5.079892s bind_call 631.582B (± 1.1%) i/s (0.00 ns/i) - 3.157T in 4.998908s __class__ 750.398B (± 1.3%) i/s (0.00 ns/i) - 3.751T in 4.999106s ``` BasicObject are very difficult to use because they miss so many "standard" methods from Kernel. As such I see them as mostly meant to proxy all the Kernel methods to maybe some delegate object or so, and the responsability of the BasicObject subclass to implement Kernel-like methods to make the object usable in normal Ruby code. ---------------------------------------- Feature #6478: BasicObject#__class__ https://bugs.ruby-lang.org/issues/6478#change-116335 * Author: trans (Thomas Sawyer) * Status: Feedback * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- How else is one supposed to get the class of a subclass of BasicObject? -- https://bugs.ruby-lang.org/
participants (1)
-
Eregon (Benoit Daloze)