Project

General

Profile

Bug #14895

Updated by sawa (Tsuyoshi Sawada) about 4 years ago

Constants defined in the namespace of a class or a module are named on the fly: 

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

 Constants defined on a singleton class seem to differ. Modules are named only after a module is created through the `module` keyword. 

 ```ruby 
 s irb(main):005:0> x = Object.new.singleton_class Object.new 
 s.const_set(:Z, => #<Object:0x000055886ee2b110> 
 irb(main):006:0> x.singleton_class.const_set(:Z, Module.new) # 
 => #<Module:0x000055886ec59a80> 
 s.class_eval irb(main):007:0> x.singleton_class.class_eval "module A; self end" # 
 => #<Class:0x000055886ec59d00>::A 
 s.const_set(:B, irb(main):008:0> x.singleton_class.const_set(:B, Module.new) # 
 => #<Class:0x000055886ec59d00>::B 
 ``` 

 I would expect module `Z` to be named. 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? 

 This also Also happens in these ruby versions: 

 * ruby 
 `ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] [x86_64-linux]` 
 * ruby `ruby 2.5.1p57 (2018-03-29 revision 63029) [i386-mingw32] [i386-mingw32]`

Back