From: marcandre-ruby-core@...
Date: 2020-09-01T04:50:43+00:00
Subject: [ruby-core:99812] [Ruby master Bug#14895] Inconsistent constant names when using const_set on a singleton class

Issue #14895 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Closed to Open

jeremyevans0 (Jeremy Evans) wrote in #note-6:
> Output:
> 
> ```
> a # #<Class:#<Object:0x0000003003436178>>::A
> b # #<Class:#<Object:0x0000003003436178>>::B
> c # #<Class:#<Object:0x0000003003436178>>::C
> ```
> 
> I kind of prefer this as it shows the module is defined under a singleton class. 

... and it shows the name 'A' and 'C'. That's much better!

>  If you like that idea, please submit a feature request for it (or switch this to a feature request and reopen).

...or consider the current output a bug (even if now it is consistently buggy ����)

```ruby
class << o
  module Bar
  end
end
o.singleton_class::Bar # => #<Class:0x00007f90f3300008>::Bar
```

So I suggest I'll commit your patch, unless there's an objection.

----------------------------------------
Bug #14895: Inconsistent constant names when using const_set on a singleton class
https://bugs.ruby-lang.org/issues/14895#change-87334

* Author: silver_phoenix (Pedro Pinto)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
```
irb(main):001:0> class X; end
=> nil
irb(main):002:0> X.const_set(:Y, Module.new)
=> X::Y
irb(main):003:0> module M; end
=> nil
irb(main):004:0> M.const_set(:N, Module.new)
=> M::N
irb(main):005:0> x = Object.new
=> #<Object:0x000055886ee2b110>
irb(main):006:0> x.singleton_class.const_set(:Z, Module.new)
=> #<Module:0x000055886ec59a80>
irb(main):007:0> x.singleton_class.class_eval "module A; self end"
=> #<Class:0x000055886ec59d00>::A
irb(main):008:0> x.singleton_class.const_set(:B, Module.new)
=> #<Class:0x000055886ec59d00>::B
```

I would expect module `Z` to be named, but the modules only start being named after creating module `A` through the `module` builtin.

For consistency, if module `B` is named, shouldn't module `Z` be named as well?

Also happens in these ruby versions:
`ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]`
`ruby 2.5.1p57 (2018-03-29 revision 63029) [i386-mingw32]`



-- 
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>